我在stackoverflow上找到了各种针对iPhone的电话号码验证,但似乎没有一个可以验证,只是改变格式。例如:电话号码格式。
目标:通过警报输入该号码。北美格式,带或不带破折号。
我有一些代码,但所有内容都无效,有什么想法吗?
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSString *str=@"^\\+(?:[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);
}
}