iOS 正则表达式判断是否为全汉字,全字母,全数字,数字和字母
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;
}