Hi how can I validate email address, username, fullname and date of birth for my registration form inside an iphone application.
+4
A:
You can use NSPredicate with regular expressions in iPhone OS > 3.0 like so
- (BOOL) validateEmail: (NSString *) candidate {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:candidate];
}
Submerged
2010-05-18 11:35:09
thanks for the reply. Is there a way we can test phone numbers as well. I have a field which takes phone number as an input and I need to know whether he provided correct phone number. something like ping a phone number functionality.
Ayaz Alavi
2010-05-18 13:36:14
To test phone numbers, the general rule is if it follows a certain format, it's valid. For security reasons, I am fairly certain that you can't "ping a phone". The only way to test it would be to have a database of customer phone records, but again...not something publicly available
Submerged
2010-05-21 12:00:36