I have to validate phone no from following 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;
}
I'm getting the following exception :
'NSInvalidArgumentException' 'Can't do regex matching, reason: (Can't open pattern U_REGEX_RULE_SYNTAX (string 6789054321, pattern +[?][0-9]{0,3}( |-)?[0-9]{4}( |-)?[0-9]{3}( |-)?[0-9]{3}, case 0, canon 0))'