Skip to content

Instantly share code, notes, and snippets.

@zhangwc
Created August 27, 2013 06:25
Show Gist options
  • Save zhangwc/6350236 to your computer and use it in GitHub Desktop.
Save zhangwc/6350236 to your computer and use it in GitHub Desktop.
// 正则验证
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^1\\d{10}$"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSUInteger count = [regex numberOfMatchesInString:userPhone
options:NSRegularExpressionCaseInsensitive
range:NSMakeRange(0, [userPhone length])];
// 格式验证失败
if (count != 1) {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment