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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -