我必須從以下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