Hi Allenvd
To help you understand the preg_replace() function, check out this website:
http://www.tote-taste.de/X-Project/regex/index.php
If anything is still unclear, let me know and I'll see if I can help.
Regarding your code, consider the following:
if (isset($_REQUEST['telw']) // You can check for this if you like, but it should always exist because of the form submit, so there isn't much point.
Maybe try handling each field individually, check all of them, and then notify the user of all errors in one go. As a suggestion:
$errmsg = ""; //Initialise variable to null
if (empty($_REQUEST['telw'])) // Not entered
$errmsg .= "Work telephone number required<p>"; // 1st level err
else // something was entered. lets check further
{
$vtelw = str_replace("(","",$_REQUEST['telw']); // Whatever string manipulation
$vtelw = str_replace("
","",$vtelw);
if (!is_numeric($vtelw)) // Further check
{
$errmsg .= "Invalid Work Telephone Number<p>";
}
} // Finished with first field
if (empty($_REQUEST['cell'])) // Not entered
$errmsg .= "Cellphone number required<p>"; // 1st level err
else // something was entered. lets check further
{
$vcell = str_replace("(","",$_REQUEST['cell']); // Whatever string manipulation
$vcell= str_replace("
","",$vcell);
if (!is_numeric($vcell)) // Further check
{
$errmsg .= "Invalid Cellphone Number<p>";
}
} // Finished with second field etc. etc. etc.
if (!$errmsg) // No errors encountered
{
echo "Form processed ok";
// Save to database etc.
}
else
{
echo "The following errors were encountered:<p>";
echo $errmsg;
}
Hope this make sense!
Regards,
Dennis