Validate phone number ios Validate phone number ios ios ios

Validate phone number ios


NSString *phoneRegex = @"^((\\+)|(00))[0-9]{6,14}$";

This way is bit better. Your code will work as well if you escape the "\".


Copy & Paste method to validate phone numbers:

- (BOOL)validatePhone:(NSString *)phoneNumber{    NSString *phoneRegex = @"^((\\+)|(00))[0-9]{6,14}$";    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];    return [phoneTest evaluateWithObject:phoneNumber];}

or Open source Library for validating Phone Numbers

https://github.com/iziz/libPhoneNumber-iOS


well it depends on how strict you want to be it doesn't seem like this regex is especially strict. this regex says:

start at beginning of linematch one + (or maybe 1 or 0) which seems ambiguous (but may not be depending on implementation) because the capture parentheses:() breaks up the relationship of the + and the ?possibly misplaced :match any digit 0-9 1 or 0 times 6-14 timesthen one digit 0-9then end of line.also you note that any backslash will have to be doubled... @"\b" for a word boundary. you may want to try something like...

@"\\b[\\d]{3}\\-[\\d]{3}\\-[\\d]{4}\\b"would I think match your example, but it wouldn't match(555) 555 - 5555 or555.555.5555 or+44 1865  55555