How to validate phone number in objective c? Please help
+2
A:
Frankly, don't bother. Here are some valid phone number formats:
+441234123456
0044 1234123456
01234123456
01234 123456
020 734123456
(01234) 123456
Those are all common UK formats. If you try to validate all possible formats, even if you succeed, there's no way to tell if the phone number is real except by ringing it.
Possibly you could restrict the number to all numerics with an optional leading +.
JeremyP
2010-10-15 08:53:53
+2
A:
- A solution with RegEx: http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation
- RegEx in Cocoa: http://stackoverflow.com/questions/422138/regular-expressions-in-an-objective-c-cocoa-application
Almost any phone number format can be checked this way. However, it is a bit complex if you haven't used RegEx before.
Gobra
2010-10-15 09:17:00