I need to determine whether a phone number is valid before attempting to dial it. The phone call can go anywhere in the world.
What regular expression will match valid international phone numbers?
I need to determine whether a phone number is valid before attempting to dial it. The phone call can go anywhere in the world.
What regular expression will match valid international phone numbers?
For iOS SWIFT I found this helpful,
Try the following API for phone number validation. Also this will return the Country, Area and Provider
demo https://libphonenumber.appspot.com/
git https://github.com/googlei18n/libphonenumber/releases/tag/v8.9.0
Modified @Eric's regular expression - added a list of all country codes (got them from xxxdepy @ Github. I hope you will find it helpful:
This works for me, without 00, 001, 0011 etc prefix though:
You can use the library libphonenumber from Google.
There's obviously a multitude of ways to do this, as evidenced by all of the different answers given thus far, but I'll throw my $0.02 worth in here and provide the regex below, which is a bit more terse than nearly all of the above, but more thorough than most as well. It also has the nice side-effect of leaving the country code in $1 and the local number in $2.
^\+(?=\d{5,15}$)(1|2[078]|3[0-469]|4[013-9]|5[1-8]|6[0-6]|7|8[1-469]|9[0-58]|[2-9]..)(\d+)$