[PHP] Phone number validation
Hi all, I am trying to validate phone numbers in a web form that I have created. I am using a regular expression to validate the phone number. It seems when I enter the phone number in the following ways I get errors (123) 456 7890 123 456 7890 (123) 456 - 7890 123 456-7890 I am using the ereg method in php to test the regular expression. Here is the Regular Expression that I am using to test against potential phone numbers $validPhone = ^([0-9]{3}[ ]*)?[0-9]{3}[ ]*[0-9]{4}$; By the way The phone numbers are in US format. If anyone can help me with this I would really appreciate it. Thanks, Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
On Sun, Mar 12, 2006 at 12:09:42PM -0700, Paul Goepfert wrote: Hi all, I am trying to validate phone numbers in a web form that I have created. I am using a regular expression to validate the phone number. It seems when I enter the phone number in the following ways I get errors (123) 456 7890 123 456 7890 (123) 456 - 7890 123 456-7890 Dont forget: 123.456.780 1-123-456-7890 ... $validPhone = ^([0-9]{3}[ ]*)?[0-9]{3}[ ]*[0-9]{4}$; By the way The phone numbers are in US format. With US phone numbers I always use this approach to avoid what format people use to enter the phone: - Remove any non digit $check_phone = preg_replace('/[^0-9]/', '', $phone); - If $check_phone strlen 10.. invalid - if $check_phone strlen == 11 first char == '1'.. remove it - if $check_phone strlen == 10, seems ok - possible area code check with prefix check (if have db to support that) I would even go as far as storing the phone striped of any formating and only format it when you display it. The other option would to make three seperate input fields in the form and join them together in your script: (input name=phone[area]) input name=phone[code]-input name=phone[num] Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
On 3/12/06, Curt Zirzow [EMAIL PROTECTED] wrote: On Sun, Mar 12, 2006 at 12:09:42PM -0700, Paul Goepfert wrote: Hi all, I am trying to validate phone numbers in a web form that I have created. I am using a regular expression to validate the phone number. It seems when I enter the phone number in the following ways I get errors (123) 456 7890 123 456 7890 (123) 456 - 7890 123 456-7890 Dont forget: 123.456.780 1-123-456-7890 ... $validPhone = ^([0-9]{3}[ ]*)?[0-9]{3}[ ]*[0-9]{4}$; By the way The phone numbers are in US format. With US phone numbers I always use this approach to avoid what format people use to enter the phone: - Remove any non digit $check_phone = preg_replace('/[^0-9]/', '', $phone); I just want to be sure about something. Is there a second quotation mark missing? I only count one and I added a space between the quotes. Paul - If $check_phone strlen 10.. invalid - if $check_phone strlen == 11 first char == '1'.. remove it - if $check_phone strlen == 10, seems ok - possible area code check with prefix check (if have db to support that) I would even go as far as storing the phone striped of any formating and only format it when you display it. The other option would to make three seperate input fields in the form and join them together in your script: (input name=phone[area]) input name=phone[code]-input name=phone[num] Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
On Sun, Mar 12, 2006 at 01:48:28PM -0700, Paul Goepfert wrote: On 3/12/06, Curt Zirzow [EMAIL PROTECTED] wrote: With US phone numbers I always use this approach to avoid what format people use to enter the phone: - Remove any non digit $check_phone = preg_replace('/[^0-9]/', '', $phone); I just want to be sure about something. Is there a second quotation mark missing? I only count one and I added a space between the quotes. I'm not sure what you're seeing but the line reads like this: http://pastebin.com/598522 Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
I didn't realize that those were single quotes. I printed out the email message and it looked like one set of double quotes for the second parameter rather the two single quotes. Is it possible for anyone to tell me what php method is used to grab the first charater of a string? And onece I have it what method removes the characted or number? I know this seems trivial but I am still new to php and I don't have a good understanding of the language yet. The more I do the better I'll get. Thanks Paul On 3/12/06, Curt Zirzow [EMAIL PROTECTED] wrote: On Sun, Mar 12, 2006 at 01:48:28PM -0700, Paul Goepfert wrote: On 3/12/06, Curt Zirzow [EMAIL PROTECTED] wrote: With US phone numbers I always use this approach to avoid what format people use to enter the phone: - Remove any non digit $check_phone = preg_replace('/[^0-9]/', '', $phone); I just want to be sure about something. Is there a second quotation mark missing? I only count one and I added a space between the quotes. I'm not sure what you're seeing but the line reads like this: http://pastebin.com/598522 Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
Paul: Also check out: http://www.weberdev.com/get_example-3605.html tedd Hi all, I am trying to validate phone numbers in a web form that I have created. I am using a regular expression to validate the phone number. It seems when I enter the phone number in the following ways I get errors (123) 456 7890 123 456 7890 (123) 456 - 7890 123 456-7890 I am using the ereg method in php to test the regular expression. Here is the Regular Expression that I am using to test against potential phone numbers $validPhone = ^([0-9]{3}[ ]*)?[0-9]{3}[ ]*[0-9]{4}$; By the way The phone numbers are in US format. If anyone can help me with this I would really appreciate it. Thanks, Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
On 3/12/06, tedd [EMAIL PROTECTED] wrote: Paul: Also check out: http://www.weberdev.com/get_example-3605.html tedd Hi all, I am trying to validate phone numbers in a web form that I have created. I am using a regular expression to validate the phone number. It seems when I enter the phone number in the following ways I get errors (123) 456 7890 123 456 7890 (123) 456 - 7890 123 456-7890 I am using the ereg method in php to test the regular expression. Here is the Regular Expression that I am using to test against potential phone numbers $validPhone = ^([0-9]{3}[ ]*)?[0-9]{3}[ ]*[0-9]{4}$; By the way The phone numbers are in US format. If anyone can help me with this I would really appreciate it. Thanks, Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- One suggestion is to have 1 field for all countries, I believe the total is 23? +011-049-069-13788-1234 http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html
Re: [PHP] Phone number validation
Paul Goepfert [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I didn't realize that those were single quotes. I printed out the email message and it looked like one set of double quotes for the second parameter rather the two single quotes. Is it possible for anyone to tell me what php method is used to grab the first charater of a string? And onece I have it what method removes the characted or number? I know this seems trivial but I am still new to php and I don't have a good understanding of the language yet. The more I do the better I'll get. Thanks Paul check out this page of the php manual for a few ideas. See the section String access and modification by character http://www.php.net/manual/en/language.types.string.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Phone number validation
I do this for phone numbers: $row['mobile'] = ereg_replace([^0-9], '', $_POST['mobile']); if ((strlen($phone)) = 14) return preg_replace (/[^0-9]*([0-9]{3})[^0-9]*([0-9]{3})[^0-9]*([0-9]{4}).*/, (\\1) \\2-\\3, $phone); Is it possible for anyone to tell me what php method is used to grab the first charater of a string? And once I have it what method removes the characted or number? $foo = 'this is a string'; $foo[0] == 't'; -Original Message- From: tedd [mailto:[EMAIL PROTECTED] Sent: Sunday, March 12, 2006 2:20 PM To: php-general@lists.php.net; Paul Goepfert Subject: Re: [PHP] Phone number validation Paul: Also check out: http://www.weberdev.com/get_example-3605.html tedd Hi all, I am trying to validate phone numbers in a web form that I have created. I am using a regular expression to validate the phone number. It seems when I enter the phone number in the following ways I get errors (123) 456 7890 123 456 7890 (123) 456 - 7890 123 456-7890 I am using the ereg method in php to test the regular expression. Here is the Regular Expression that I am using to test against potential phone numbers $validPhone = ^([0-9]{3}[ ]*)?[0-9]{3}[ ]*[0-9]{4}$; By the way The phone numbers are in US format. If anyone can help me with this I would really appreciate it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP Phone Number Validation
-Original Message- From: IMEX Research [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 17, 2005 2:49 AM To: php-general@lists.php.net Subject: [PHP] PHP Phone Number Validation OK, I know this has probably gone aruond the list a few times, but how do I validate a phone number that is in the format ddd-ddd- ?? I can't figure out how. With regular expressions: http://dk.php.net/manual/en/function.ereg.php http://dk.php.net/manual/en/function.preg-match.php I expect You wanna match 555-666-0606? (Angelina Jolies number ;-) This will match the number from start to end: ^[0-9]{3}-[0-9]{3}-[0-9]{5}$ ^ means the start of the string $ means the end of the string [0-9] means any number from 0 to 9 {3} means _exactly_ 3 occurences, no more no less (can also be {2,4} if You world allow from 2 to 4 occurences or {2,} if You want at least 2 digits) So this line says _start_ with 3 digits followed by a - then 3 digits, then another - and end with 4 digits Example: $number = 555-666-0606; if(ereg(^[0-9]{3}-[0-9]{3}-[0-9]{4}$, $number)) { echo valid phonenumber; } else { echo invalid phonenumber; } -- Med venlig hilsen / best regards ComX Networks A/S Kim Madsen Systemudvikler/Systemdeveloper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Phone Number Validation
IMEX Research wrote: OK, I know this has probably gone aruond the list a few times, but how do I validate a phone number that is in the format ddd-ddd- ?? I can't figure out how. preg_match ( /^\d{3}-\d{3}-\d{4}$/, $phnumber ) -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Phone Number Validation
On 05/16/2005 7:48 PM, IMEX Research [EMAIL PROTECTED] wrote: OK, I know this has probably gone aruond the list a few times, but how do I validate a phone number that is in the format ddd-ddd- ?? I can't figure out how. I try to not restrict the way your users enter phone numbers or other types of structured data. I wouldn't bother validating against ddd-ddd- unless you also plan on validating (ddd) ddd-, ddd.ddd., +1 ddd ddd ddd or any number of variations. Your best bet is to make sure that the number contains 10 (or 11) digits: $phone = preg_replace('/[^0-9]/', '', $phone); # remove non-numbers if (preg_match('/^1?[0-9]{10}$/', $phone)) { echo 'Valid'; } To answer your original question: if (preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) { echo 'Valid'; } Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP Phone Number Validation
OK, I know this has probably gone aruond the list a few times, but how do I validate a phone number that is in the format ddd-ddd- ?? I can't figure out how. Jeremy White IMEX Research Manager, Online Marketing 408-268-0800 1474 Camino Robles San Jose, CA 95120 [EMAIL PROTECTED] http://www.imexresearch.com
Re: [PHP] Phone number validation
try this preg_match(/[a-zA-Z]+/i, $str); and if you want to go the other route. do this preg_match(/[^0-9\(\)\-\.\ ]+/i, $str); this will return true if it is anything other then what is listed. numbers 0-9 ( ) - . Jim Lucas - Original Message - From: Gary [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, April 06, 2002 6:52 PM Subject: [PHP] Phone number validation Hi All, I tried to cut a corner and use an alphabetic validation I am using elsewhere $stuff = /^[a-zA-Z]+$/; if(preg_match($stuff, $value)) looks like I forgot about +( )- being in phone number. What is the easiest way to allow these 4 characters? Are there any other characters that people use? TIA Gary -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
Richard Baskett [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... What I do is strip all non-numeric numbers out and just store the number as a string of numbers.. Then do validation on those numbers.. Make sure the right amount of numbers are there, valid country, city codes etc. Probably an easier approach :) Just as a curiosity - (I dont need / Want it now - Maybe later) Where / what site, can we get a list of the valid country/city codes ? G. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
http://www.the-acr.com/codes/cntrycd.htm Rick A good head and good heart are always a formidable combination. But when you add to that a literate tongue or pen, then you have something very special - Nelson Mandela From: Gordon Stewart [EMAIL PROTECTED] Date: Mon, 8 Apr 2002 00:50:09 +1200 To: [EMAIL PROTECTED] Subject: Re: [PHP] Phone number validation Richard Baskett [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... What I do is strip all non-numeric numbers out and just store the number as a string of numbers.. Then do validation on those numbers.. Make sure the right amount of numbers are there, valid country, city codes etc. Probably an easier approach :) Just as a curiosity - (I dont need / Want it now - Maybe later) Where / what site, can we get a list of the valid country/city codes ? G. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
On Mon, 8 Apr 2002, Gordon Stewart wrote: Just as a curiosity - (I dont need / Want it now - Maybe later) Where / what site, can we get a list of the valid country/city codes ? Someone else has already provided you with a site. I'd just add that validating international numbers against any sort of list is bound to lead to extreme annoyance. Even telephone companies have trouble keeping track of changes. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
I would agree with that. When I wrote that you COULD do that.. I didn¹t mean that I do that :) If you wanted to get down and dirty and verify everything about that phone number you could.. Was what I was trying to get at. But when you had all the non-numeric characters in a phone number it makes it hard to do any type of verification since everyone seems to write their phone numbers different. Thus the reason for my advice on stripping all non-numeric characters from the phone number before checking to make sure it's a valid number or throwing it into your database in the format you want. Verifying country, city, etc codes would just be a royal pain in the @$$ and I wouldn¹t recommend it to anyone, there really is no reason to do it, but you COULD do it if you really wanted :) Cheers! Rick Every person you meet - and everything you do in life - is an opportunity to learn something. - Tom Clancy From: Miguel Cruz [EMAIL PROTECTED] Date: Sun, 7 Apr 2002 14:08:42 -0500 (CDT) To: Gordon Stewart [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Phone number validation On Mon, 8 Apr 2002, Gordon Stewart wrote: Just as a curiosity - (I dont need / Want it now - Maybe later) Where / what site, can we get a list of the valid country/city codes ? Someone else has already provided you with a site. I'd just add that validating international numbers against any sort of list is bound to lead to extreme annoyance. Even telephone companies have trouble keeping track of changes. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
Miguel Cruz wrote: On Mon, 8 Apr 2002, Gordon Stewart wrote: Just as a curiosity - (I dont need / Want it now - Maybe later) Where / what site, can we get a list of the valid country/city codes ? Someone else has already provided you with a site. I'd just add that validating international numbers against any sort of list is bound to lead to extreme annoyance. Even telephone companies have trouble keeping track of changes. miguel I have to agree with that. I have given up on validating a phone number. When I sat down and thought about it there are too many problems. These problems range from country codes, city codes , and area codes all changing daily to business phones. Your looking at #*. + ( )- and probably many more I haven't thought of. Looks like I will only check if something is there. Gary -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Phone number validation
Hi All, I tried to cut a corner and use an alphabetic validation I am using elsewhere $stuff = /^[a-zA-Z]+$/; if(preg_match($stuff, $value)) looks like I forgot about +( )- being in phone number. What is the easiest way to allow these 4 characters? Are there any other characters that people use? TIA Gary -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
Some people use period '.' in between fields...me for one. Its an old habit I have although I forget where I picked that up from. I am sure it was when I was working overseas...maybe Asia where I saw all phone numbers using . between fields. - Original Message - From: Gary [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, April 06, 2002 8:52 PM Subject: [PHP] Phone number validation : Hi All, : I tried to cut a corner and use an alphabetic validation I am using : elsewhere : $stuff = /^[a-zA-Z]+$/; : if(preg_match($stuff, $value)) : : looks like I forgot about +( )- being in phone number. What is the : easiest way to allow these 4 characters? Are there any other characters : that people use? : : TIA : Gary : : : -- : PHP General Mailing List (http://www.php.net/) : To unsubscribe, visit: http://www.php.net/unsub.php : : -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
FWIW, In Australia, phone numbers are commonly formatted with brackets for area codes: (03) 9876 5432 +61 (3) 9876 5432 +61 3 9876 5432 Also the usual array of +,-,.,etc I'd include ()'s in your reg exp for sure. Justin on 07/04/02 1:47 PM, Jason Cribbins ([EMAIL PROTECTED]) wrote: Some people use period '.' in between fields...me for one. Its an old habit I have although I forget where I picked that up from. I am sure it was when I was working overseas...maybe Asia where I saw all phone numbers using . between fields. - Original Message - From: Gary [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, April 06, 2002 8:52 PM Subject: [PHP] Phone number validation : Hi All, : I tried to cut a corner and use an alphabetic validation I am using : elsewhere : $stuff = /^[a-zA-Z]+$/; : if(preg_match($stuff, $value)) : : looks like I forgot about +( )- being in phone number. What is the : easiest way to allow these 4 characters? Are there any other characters : that people use? : : TIA : Gary : : : -- : PHP General Mailing List (http://www.php.net/) : To unsubscribe, visit: http://www.php.net/unsub.php : : -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Phone number validation
What I do is strip all non-numeric numbers out and just store the number as a string of numbers.. Then do validation on those numbers.. Make sure the right amount of numbers are there, valid country, city codes etc. Probably an easier approach :) Rick Nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education alone will not; the world is full of educated derelicts. Persistence and determination alone are omnipotent. - Calvin Coolidge From: Jason Cribbins [EMAIL PROTECTED] Reply-To: Jason Cribbins [EMAIL PROTECTED] Date: Sat, 6 Apr 2002 22:47:46 -0500 To: [EMAIL PROTECTED], Gary [EMAIL PROTECTED] Subject: Re: [PHP] Phone number validation Some people use period '.' in between fields...me for one. Its an old habit I have although I forget where I picked that up from. I am sure it was when I was working overseas...maybe Asia where I saw all phone numbers using . between fields. - Original Message - From: Gary [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, April 06, 2002 8:52 PM Subject: [PHP] Phone number validation : Hi All, : I tried to cut a corner and use an alphabetic validation I am using : elsewhere : $stuff = /^[a-zA-Z]+$/; : if(preg_match($stuff, $value)) : : looks like I forgot about +( )- being in phone number. What is the : easiest way to allow these 4 characters? Are there any other characters : that people use? : : TIA : Gary : : : -- : PHP General Mailing List (http://www.php.net/) : To unsubscribe, visit: http://www.php.net/unsub.php : : -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php