Re: [PHP] validate international phone numbers
Merlin wrote: Hi, I am trying to validate international phone numbers before adding into a db. After a bit of research I came up with this regex: return (ereg('^[0-9]{1,3}\.[0-9]{1,6}\.[0-9]{1,8}$', $phone)); However, this tightens the numbers to something like this: 409.711.933838 Thats a problem, since some countries have complete other formats and some peopole place a + in front and a : instead of . or even just the number. Can anybody recommend a good regex to validate this? I am not to good at creating regex :-( Strip out all non-numerical characters before you process. Sincerely, Joshua D. Drake Thanx for any help, Merlin -- Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC Postgresql support, programming shared hosting and dedicated hosting. +1-503-667-4564 - [EMAIL PROTECTED] - http://www.commandprompt.com PostgreSQL Replicator -- production quality replication for PostgreSQL -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] validate international phone numbers
> -Original Message- > From: Merlin [mailto:[EMAIL PROTECTED] > Sent: 02 November 2004 10:49 > To: [EMAIL PROTECTED] > Subject: [PHP] validate international phone numbers > > > Hi, > > I am trying to validate international phone numbers before adding > into a db. > After a bit of research I came up with this regex: > > return (ereg('^[0-9]{1,3}\.[0-9]{1,6}\.[0-9]{1,8}$', $phone)); > However, this tightens the numbers to something like this: 409.711.933838 > > Thats a problem, since some countries have complete other formats > and some > peopole place a + in front and a : instead of . or even just the number. > > Can anybody recommend a good regex to validate this? I am not to good at > creating regex :-( > > Thanx for any help, > > Merlin I know this is not exactly what you were asking, but, some time ago I did some phone number validation/formatting but not in PHP. IIRC I had a list of countries each of which had the relevant international dialling code recorded. The user of a form would select their country and enter a telephone number. The international dialling code would be added if not present or validated if '+' was present. Any leading 0 (after an int. code) would be removed. Beyond that I think all you can do is validate that a certain number of digits must have been entered as different people/countries use different formatting chars: space , . - : etc etc Another approach would be to request each component separately: int.code, area code, local number. This of course was all done within a function/class not a single statement. HTH Graham -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] validate international phone numbers
On Tuesday 02 November 2004 10:49, Merlin wrote: > I am trying to validate international phone numbers before adding into a > db. After a bit of research I came up with this regex: > > return (ereg('^[0-9]{1,3}\.[0-9]{1,6}\.[0-9]{1,8}$', $phone)); > However, this tightens the numbers to something like this: 409.711.933838 > > Thats a problem, since some countries have complete other formats and some > peopole place a + in front and a : instead of . or even just the number. > > Can anybody recommend a good regex to validate this? I am not to good at > creating regex :-( Using a single regex which encompasses all formats of telephone numbers used throughout the world will result in something that is pretty much useless. I would just check that their entry consists only of digits, space, hyphen, plus sign and period. Otherwise create an individual check for each country in the world that you're interested in. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* No one so thoroughly appreciates the value of constructive criticism as the one who's giving it. -- Hal Chadwick */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php