RE: [PHP] Regex for telephone number
| From: | Jason Murray | Date: | Tue, 16 Jan 2001 05:06:03 +0000 |
| Subject: | RE: [PHP] Regex for telephone number | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-34764@lists.php.net to get a copy of this message | ||
> 123 4567
> 1234567
> +91 44 123 4567
> +91 44 1234567
> 91-44-123 4567
> 91-44-1234567
So, 91441234567 and 9 1 4 4 1 2 3 4 5 6 7 aren't valid?
You *could* apply a rule here, but it's fallible.
1. Strip out everything thats not a number (ereg_replace("[^0-9]", "")).
2. Count the number of digits.
a. If there's less than 7 digits, its invalid.
b. 7 digits is valid, local number format.
c. 8, 9, and 10 digit numbers are invalid.
d. 11 digits is valid, international format.
Of course, if someone has a mobile phone this will fall flat on its
face (in Australia, our phone numbers have 8 digits and our mobiles
have 10 digits - this is the same in a number of countries).
My advice, check that there's at least 7 digits and let it go.
Jason
--
Jason Murray
jasonm@melbourneit.com.au
Web Design Team, Melbourne IT
Fetch the comfy chair!