NSPredicate for phone number
ios, nspredicate
Solution
Replace your pNRegex with this,
NSString *pNRegex = @"^(\\([0-9]{3}\\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$";
Hope it helps you.
Problem
My phone number format is (987) 786-5645. ``` - (BOOL)validatePhoneNumberWithString:(NSString*)phone { NSString *pNRegex = @"[(0-9)]{3}+\\ +\\[0-9-]{3}+\\[0-9]{4}"; NSPredicate *PNTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pNRegex]; return [PNTest evaluateWithObject:phone]; } ``` I am using above code. What should be the exact regex rule for this? I am able to figure out digits, and brackets also. What should I use for detecting that whitespace after closing bracket?