I have a preg_match that is used to verify that a form had a valid phone number. I understand some of what I have, but not all. I want to be able to accept the form with the phone number blank (I am asking for several different phone numbers that not everyone will have). The first number I ask for is a fax number.
if (preg_match ('%^([0-9]( |-)?)?(\\(?[0-9]{3}\\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})$%', stripslashes(trim($_POST['fax'])))) {
$fax = escape_data($_POST['fax']);
} else {
$fax = FALSE;
echo '<p style="color:red;">Please enter a valid fax number!</p>';
} // end of check for fax
It starts of with ‘%^ what does this mean/do? It ends with $%’ and again I do not know what it means/does. (could it be similar to <?php and ?> to start and end that section?)
I get that only 0-9 is accepted then I do not know what is happening again until I get to the second [0-9].
I think {3} is requiring three digits, then more I do not know.
Toward the last, it looks like I could accept a seven character phone of SK12345 or even ABCDEFG.
Does ( |-) indicate that either a space of a dash are acceptable at a specific location?