hola,
I'm trying to get a regular expression to work for validating a phone number field from form input, I've tired using a bunch of the different phone number regexp listed here: http://regexplib.com/
but so far no luck
code:
verify.php
<?php
function verify_email($email) {
return (preg_match("/^\w[^@\s]*\w@\w([\w\.]*\w)?\.\w{2,}$/", $email));
}
function verify_phone($phone) {
return (preg_match("^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$", $phone));
}
function verify_text($text){
return (preg_match("^([1-zA-Z0-1@.\s]{1,1000})$", $text));
}
?>
relevent portion of send.php
if(!verify_email($_POST['email'])){
echo "bad email";
exit;
}
if(!verify_phone(stripslashes($_POST['phone']))){
echo "bad phone number";
exit;
}
now the verify_email works as expected, but verify_phone returns "bad phone number" regardless of the content of the field. Am I doing something wrong/not seeing a stupid error? (I really can't believe that all 6 of the regexp I tried from regexplib are wrong).
Thanks!