PHP (RegEx) Telephone Number Validation

/ Published in: PHP
Save to your folder(s)

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

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.