Reputation: 1146
I have an application that has records of multiple countries' users.And I am recording the phone no. of each user.And i want to apply validation on phone no country wise format.
Thanks!
Upvotes: 1
Views: 1046
Reputation: 8121
PhoneFormat.com has a javascript library that will do exactly what your looking for. You can pass it a phone number in any format, and it will return the country code, and also convert it to e164 and it can format it too.
Upvotes: 1
Reputation: 37378
Validating the format 100% will be near impossible, you will have to make some sacrifices.
I only know about UK phone numbers, but there are countless possible valid number formats, and different ways of representing them, eg:
+44 2345 123 456
02345123456
1234 56 78
your best bet would be to validate it only contains numbers and spaces, starts with a +. it could also contain a # for extensions?
some simple regex would be:
/\+?[\d+](\#\d+)?/i
Upvotes: 0