ios - NSPredicate for phone number -
my phone number format (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 using above code.
what should exact regex rule this? able figure out digits, , brackets also.
what should use detecting whitespace after closing bracket?
replace pnregex this,
nsstring *pnregex = @"^(\\([0-9]{3}\\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$";
hope helps you.
Comments
Post a Comment