Regular expression for validating numbers

Rated 4.81/5 based on 899 customer reviews

It also has the nice side-effect of leaving the country code in

It also has the nice side-effect of leaving the country code in $1 and the local number in $2. =\d$)(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 )$ ^ - start of expression (?!

||

It also has the nice side-effect of leaving the country code in $1 and the local number in $2. =\d$)(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 )$ ^ - start of expression (?!

The literal “x” character is required only if an extension is provided. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

The last question mark is to make country code optional. The leading plus sign and the dot following the country code are required.

and the local number in . =\d$)(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 )$ ^ - start of expression (?!

Even though this is not really using Reg Exp to get the job done - or maybe because of that - this looks like a nice solution to me: https://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/Try the following API for phone number validation. I'll update this if I get around to create a regular expression based on the ITU E.164 numbering. I guess that's the starting point to your regular expression.Note that if you enter numbers in this format into your mobile phone address book, you may successfully call any number in your address book no matter where you travel. For land lines, replace the plus with the international access code for the country you are dialing from. It contains all current country codes and codes reserved for future use.

Leave a Reply