if ([self deptNameInputShouldChinese]) {
[DemonAlertHelper showToastWithMessage:@"只能是中文"];
return;
}
调用这个方法就可
#pragma mark--
#pragma mark 输入中文
- (BOOL) deptNameInputShouldChinese
{
NSString *regex = @"[\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if (![pred evaluateWithObject:inputTextField.text]) {
return YES;
}
return NO;
}
判断全数字:
- (BOOL) deptNumInputShouldNumber
{
NSString *regex =@"[0-9]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if (![pred evaluateWithObject:inputTextField.text]) {
return YES;
}
return NO;
}
判断全字母:
- (BOOL) deptPassInputShouldAlpha
{
NSString *regex =@"[a-zA-Z]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if (![pred evaluateWithObject:inputTextField.text]) {
return YES;
}
return NO;
}
判断仅输入字母或数字:
- (BOOL) deptIdInputShouldAlphaNum
{
NSString *regex =@"[a-zA-Z0-9]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if (![pred evaluateWithObject:inputTextField.text]) {
return YES;
}
return NO;
}