tags:

views:

29

answers:

1

This is the code I am working on

 if(trim($_POST['phone']) == '')  {
      $hasError = true;
      print "phone number empty";
     } else if (!eregi("^\(?[\d]{3}\)?[\s-]?[\d]{3}[\s-]?[\d]{4}\s*$", trim($_POST['phone']))) { // if I am right this should validate all U.S. numbers
      $hasError = true;
      print "phone number does not match regular expression";
     } else {
      $phone = trim($_POST['phone']);
     }

I use the number 555-555-5555 and it is catches on the if loop after checking the regular expression and prints the statement "phone number does not match regular expression". I have tested it out at http://regexpal.com/ and it says everything is hunky dory... Any ideas what I am doing wrong?

A: 

You should search for already done solutions, something as simple as a phone number has been done by thousands of programmers before you.

The other problem, is that you're using a depricated function. Stop that. Use preg, not eregi.