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?