判斷全漢字(這個問題苦惱了我好久,如今很方便,幾行代碼就搞定):lua
if ([self deptNameInputShouldChinese]) {spa
[DemonAlertHelper showToastWithMessage:@"只能是中文"];3d
return;orm
}input
調用這個方法就可it
#pragma mark--ast
#pragma mark 輸入中文方法
- (BOOL) deptNameInputShouldChinesemargin
{top
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;
}