验证ios中的电话号码

Vib*_*oti -1 iphone validation objective-c nspredicate ios

我在验证电话号码时遇到了问题,(999) 855-6666
如何验证(xxx) xxx-xxxxiOS格式的电话号码?

Man*_*ani 7

尝试使用正则表达式.如果你的字符串是这种格式(xxx)xxx-xxxx,它将成为现实.否则失败,即使它有空间.

NSString *phoneRegex = @"^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
BOOL phoneValidates = [phoneTest evaluateWithObject:phoneNumber];
Run Code Online (Sandbox Code Playgroud)

看到这个正则表达式.