Possible Duplicate:
A comprehensive regex for phone number validation
How to validate a phone number (NSString *) in objective-c? Rules:
- minimum 7 digits
- maximum 10 digits
- the first digit must be 2, 3, 5, 6, 8 or 9
Thanks
Possible Duplicate:
A comprehensive regex for phone number validation
How to validate a phone number (NSString *) in objective-c? Rules:
Thanks
For those searching for phone extraction, you can extract the phone numbers from a text, for example:
NSString *userBody = @"This is a text with 30612312232 my phone";
if (userBody != nil) {
NSError *error = NULL;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypePhoneNumber error:&error];
NSArray *matches = [detector matchesInString:userBody options:0 range:NSMakeRange(0, [userBody length])];
if (matches != nil) {
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypePhoneNumber) {
DbgLog(@"Found phone number %@", [match phoneNumber]);
}
}
}
}
`