Php validating phone number regex

04-Jul-2020 05:55

I replaced the US land line centric international access code 011 with the standard international access code identifier of ' ', making it mandatory.

I also changed the minimum for the national number to at least one digit.

Strictly speaking, integers are whole numbers positive and negative, and also including zero.

Here is a regular expression for this: Note that this will allow for values such as -0000, which does not cause problems in PHP, however.

To restrict this, you would change the star into a length restriction like so: This would allow the string to be between 1 and 16 digits long (ie the first digit plus 0-15 further digits).

Feel free to adjust the numbers in the curly braces to suit your own needs.

This means a three digit country code results in up to 12 additional digits, and a 1 digit country code could contain up to 14 additional digits.

Is the correct format for matching a generic international phone number. ' plus sign before country code is optional.\d - country code can be 1 to 3 digits long. Would you like to answer one of these unanswered questions instead?

Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Hexadecimal notation (0x FF) is allowed too but only without sign, decimal and exponential part.

PHP's is_numeric function allows for floats as well as integers.

Also this will return the Country, Area and Provider demo git The format CCC. NNNNNNNNNNx EEEE Phone number must start with ' ' or '00' for an international call.

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: the following API for phone number validation. The last question mark is to make country code optional. The leading plus sign and the dot following the country code are required.