php - regex to validate phone number -
php - regex to validate phone number -
help me write regex below conditions
number can start + number can contain - or . not () , / number can start 0 min number in string should 9 digits excluding extension details , starting + max number in phone number field should not reach more 14 excluding + if string contains ex/ext/x digit after should not have more 5 characters (normally 4)this above should satisfy examples below
0-1234-123456 +91-1234-56789012 +91-1234-56789012 x1234 +91-1234-56789012 ex1234 +91-1234-56789012 ext12345 +91-1234-56789012x1234 +91-1234-56789012ex1234 +91-1234-56789012ext12345 91-1234-56789012 91-1234-56789012 x1234 91-1234-56789012 ex1234 91-1234-56789012 ext12345 91-1234-56789012x1234 91-1234-56789012ex1234 91-1234-56789012ext12345 91123456789012 91123456789012 x1234 91123456789012 ex1234 91123456789012 ext12345 91123456789012x1234 91123456789012ex1234 91123456789012ext12345 91.1234.56789012 91.1234.56789012 x1234 91.1234.56789012 ex1234 91.12345.6789012 ext12345 91.12345.6789012x1234 91.12345.6789012ex1234 91.12345.6789012ext12345 1-234-567-8901 1-234-567-8901 x1234 1-234-567-8901 ext1234 1 234 567-8901 1.234.567.8901 12345678901
i found few links online 1 of them http://ericholmes.ca/php-phone-number-validation-revisited/
and on stackoverflow
a comprehensive regex phone number validation
also
^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$
is not working many of above
^\+?(\d[.\- ]*){9,14}(e?xt?\d{1,5})?$
explanation;
^
asserts start of string \+?
matches optional plus (\d[.\- ]*){9,14}
between 9 , 14 single digits, perchance seperated spaces, dots, or dashes. (e?xt?\d{1,5})?
optionally x perchance preceeded e or followed t. letters followed between 1 , 5 numbers. $
asserts end of string php regex validation phone-number
Comments
Post a Comment