iOS正则表达式

2017-10-21  本文已影响4人  ericguo

判断全汉字

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;

}

强者VS弱者

上一篇下一篇

猜你喜欢

热点阅读