Created
April 26, 2014 14:52
-
-
Save piaoapiao/11322102 to your computer and use it in GitHub Desktop.
过滤中文输入
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[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