Your Ad Here

Posted By

aristoworks on 07/01/08


Tagged

php phone number simple validation regular expressions telephone


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jdstraughan
robe
vali29


PHP (RegEx) Telephone Number Validation


 / Published in: PHP
 

URL: http://www.thejwalker.com

A simple method of validating a telephone number using regular expressions and PHP

  1. $string = "(232) 555-5555";
  2. if (preg_match('/^\(?[0-9]{3}\)?|[0-9]{3}[-. ]? [0-9]{3}[-. ]?[0-9]{4}$/', $string)) {
  3. echo "example 2 successful.";
  4. }

Report this snippet  

You need to login to post a comment.