I find all kinds of phone number validations on stackoverflow for the iphone but none seem to validate they just seem to change the format. example Phone number formatting.
Goals: this number is being entered via an alert. North American with or with out dashes.
so have some code but every thing is coming up as invalid any ideas.
- (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);
}
}
See Question&Answers more detail:os