Hello. I have been exploring data validation with PHP. I am trying to format two items, a phone number and a fax number.
When a user submits a phone or fax number, control will test if the number is valid or not.
For example, if a user enters a phone number of 5555555, control will output an error message, prompting the user to enter the phone
number in the format of 555-5555.
And when a user does this and phone number is validated, control will test the next item, which is the fax number, in the same manner.
When I test a number, code outputs the incorrect format error message to my screen, along with the PHP error..
According to my compilation, I have an unknown modifier " - " within this little block of code...
if ($phone)
{
$phone = trim($phone);
// Patterns for phone number
$_first = "([-0-9])";
$_last = "([-0-9])";
// Apply the validity check on the phone number field
if( !preg_match($_first."-".$_last,$phone) )
{
$msg = ("<font face='Arial' size='+1' color='red'>Your sign up has failed!</font><br>
<font face='Arial' color='#4D50A3' size='+1'>Your phone number information is formatted incorrectly!<br><font color='black'>Enter your phone number in the form of ###-####</font><br><br>
Click your browser 'Back' button<br><br>
or<br><br>
Click <a href='add_profile.htm'>HERE</a> to re-complete your registration.");
}
I strongly believe that the problem lies within the $first and $last variable declarations, and possibly within the preg_match line...For some reason, it's rejecting the - (dash) that should properly format the phone number...
If you guys have any suggestions, I'd be very thankful!!!
Mike