判断全汉字(这个问题苦恼了我很久,现在很方便,几行代码就搞定):
if([selfdeptNameInputShouldChinese]) {
[DemonAlertHelpershowToastWithMessage:@"只能是中文"];
return;
}
调用这个方法就可
#pragma mark--
#pragma mark输入中文
- (BOOL) deptNameInputShouldChinese
{
NSString*regex =@"[\u4e00-\u9fa5]+";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",regex];
if(![predevaluateWithObject:inputTextField.text]) {
returnYES;
}
returnNO;
}
判断全数字:
- (BOOL) deptNumInputShouldNumber
{
NSString*regex =@"[0-9]*";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",regex];
if(![predevaluateWithObject:inputTextField.text]) {
returnYES;
}
returnNO;
}
判断全字母:
- (BOOL) deptPassInputShouldAlpha
{
NSString*regex =@"[a-zA-Z]*";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",regex];
if(![predevaluateWithObject:inputTextField.text]) {
returnYES;
}
returnNO;
}
判断仅输入字母或数字:
- (BOOL) deptIdInputShouldAlphaNum
{
NSString*regex =@"[a-zA-Z0-9]*";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",regex];
if(![predevaluateWithObject:inputTextField.text]) {
returnYES;
}
returnNO;
}