禁止输入汉字

iOS———-禁止输入汉字,ios———-

说明:

^.*[\u4e00-\u9fa5].*$ 是否包含中文
^[\u4E00-\u9FA5]+$ 是否全中文

 

– (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString
*)string {
if (![string isEqualToString:@””]) {
if ([self isChinese:string]) {
return NO;
}
}
return YES;
}

  • (BOOL)isChinese:(NSString *)string {
    NSString *regex = @”^[\u4E00-\u9FA5]+$”;
    NSPredicate *pred = [NSPredicate predicateWithFormat:@”SELF MATCHES
    %@”, regex];

BOOL isMatch = [pred evaluateWithObject:string];
return isMatch;
}

说明:
^.*[\u4e00-\u9fa5]金沙手机APP,.*$ 是否包含中文 ^[\u4E00-\u9FA5]+$
是否全中文 – (BOOL)textField:(UITextField *)textField sho…

相关文章