我发现iphone上的stackoverflow的各种电话号码验证,但似乎没有任何验证,他们似乎只是改变格式。示例Phone number formatting。iPhone的简单电话号码验证
目标:通过警报输入此号码。北美有或没有破折号。
所以有一些代码,但是每件事情都会像任何想法一样无效。
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSString *[email protected]"^\\+(?:[0-9] ?){6,14}[0-9]$";
NSPredicate *no=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",str];
if([no evaluateWithObject:textField.text]==NO)
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please Enter correct contact no." delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
else{
NSString *textValue = textField.text;
NSLog(@"Value: %@", textValue);
}
}
你真的不应该限制自己这种类型的验证 - 只需使用像numverify.com这样的免费JSON API – Frank