Jump to content

Validation


bbonora

Recommended Posts

I need to validate a phone number using a if statement and a regular expression. My script will validate the number but the problem I am having is the script returns an error for every phone number field in the form. Since only one field is required I only want the script to check the number if there is something inputed in the field. Also my reg expression does not allow for spaces or dashes. It would be nice to find one that did. Here is the script I have so far. If anyone knows how to fix this I would be very appreciative.

//Check Phone numbers
$validPhoneExpr = "^([0-9]{2,3}[ ]?)?[0-9]{4}[ ]?[0-9]{4}$";
if(!ereg($validPhoneExpr,$_POST['giTelephone']))
{
$msg .="<ul><li>The \"General Information\" section has an invalid telephone number</li>";
include("apply.php");
exit();
}
if(!ereg($validPhoneExpr, $_POST['ref1Telephone']))
{
unset($_GET['do']);
$msg .="<ul><li>The \"General Information\" section has an invalid telephone number</li>";
include("apply.php");
exit();
}
}

if(!ereg($validPhoneExpr, $_POST['ref2Telephone']))
{
unset($_GET['do']);
$msg .="<li>Your second reference has an invalid telephone number</li>";
include("apply.php");
exit();
}



Thanks,
Ben
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.