RE: [PHP] verify phone number
One way: $phone = ereg_replace([^0-9], , $phone); if(!ereg(^[0-9]{10}$,$phoneHome)) { echo error; } You could also check the string length after removing all non-numbers. Kirk -Original Message- From: Claudia Smith [mailto:[EMAIL PROTECTED]] Sent: Friday, May 11, 2001 4:52 PM To: [EMAIL PROTECTED] Subject: [PHP] verify phone number I am looking for code to verify a phone number has been entered correctly on a form field. Requirements would include the area code: xxx-xxx-. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] verify phone number
I am looking for code to verify a phone number has been entered correctly on a form field. Requirements would include the area code: xxx-xxx-. You should use a regex for this. Something like... if (ereg ([0-9]{3}-[0-9]{3}-[0-9]{4}, $number)) { print good\n; } else { print bad\n; } The regexp breaks down like this: [0-9]{3}[0-9]{3}[0-9]{4} (three numbers)-(three numbers)-(four numbers) I didn't test the code above, so let me know if it won't work for you. Regards, Sean -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]