我必须从以下regEx验证电话号码。验证来自regEx的用户输入
//**regExpPattern** : "+?[0-9]{0,3}(|-)?[0-9]{4}(|-)?[0-9]{3}(|-)?[0-9]{3}"
-(BOOL) textFieldValidation:(NSString *)checkString withRegEx:(NSString*)regExpPattern
{
NSString *stringToValidate = [[NSString alloc]initWithString:checkString];
NSString *pattern = [[NSString alloc]initWithString:regExpPattern]
NSLog(@"%@ %@",checkString,regExpPattern);
NSPredicate *myTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",pattern];
if ([myTest evaluateWithObject:stringToValidate]){
return YES;
}
return FALSE;
}
,我发现了以下异常:
'NSInvalidArgumentException' “不能做正则表达式匹配,原因是:(无法打开模式U_REGEX_RULE_SYNTAX(字符串6789054321,模式+? ] [0-9] {0,3}(| - )?[0-9] {4}(| - )?[0-9] {3}(| - )?[0-9] {3} ,case 0,canon 0))'
http://stackoverflow.com/questions/3349494/objective-c-regex-to-check-phone-number – Laxmi
一个简单的..如果这可以帮助:http://www.iossnippet.com/snippets /验证/如何对验证-A-电话号码功能于目标c-IOS / – GenieWanted