Skip to content

Instantly share code, notes, and snippets.

@piaoapiao
Created April 26, 2014 14:52
Show Gist options
  • Save piaoapiao/11322102 to your computer and use it in GitHub Desktop.
Save piaoapiao/11322102 to your computer and use it in GitHub Desktop.
过滤中文输入
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFiledEditChanged:)
name:@"UITextFieldTextDidChangeNotification"
object:self.bBankCardbyName];
-(void)textFiledEditChanged:(NSNotification *)obj{
UITextField *textField = (UITextField *)obj.object;
NSLog(@"textField:%@",textField.text);
NSMutableString *mutalbleStr = [NSMutableString stringWithString:self.bBankCardbyName.text];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:
@"[\u4e00-\u9fa5]" options:0 error:nil];
[regex replaceMatchesInString:mutalbleStr options:0 range:NSMakeRange(0, [self.bBankCardbyName.text length]) withTemplate:@""];
self.bBankCardbyName.text = mutalbleStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment