Validation
Posted: Sat May 28, 2005 1:12 pm
I am trying to construct a simple form where users can enter their information. I am having an issue with the field "VIN" on this page http://www.yokokumano.com/ducati/ch08/registration.php
When there is no data in the field, an error message stops the entry from being entered into the database. But I set the parameters for 14 number digits only and even if I put the wrong amount of digits, it will enter it into the database.
When there is no data in the field, an error message stops the entry from being entered into the database. But I set the parameters for 14 number digits only and even if I put the wrong amount of digits, it will enter it into the database.
Code: Select all
if(isset($submit_button)){
if(trim($vin)=='') {
$error_msg.="Please enter a VIN<br>";
} else {
// check if vin is 14 digits
if(!ereg("[0-9]{14}", $vin)) $error_msg.="Please enter a valid VIN #<br>";
}
if(trim($email)=='') {
$error_msg.="Please enter an email<br>";
} else {
// check if email is a valid address in this format username@domain.com
if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email)) $error_msg.="Please enter a valid email address<br>";
}
// display error message if any, if not, proceed to other processing
if($error_msg==''){
// other process here
} else {
echo "<font color=red>$error_msg</font>";
}
}
if (!empty($_GET["surname"]) &&
!empty($_GET["firstname"]) &&
!empty($_GET["email"]) &&
!empty($_GET["phone"]) &&
!empty($_GET["vin"]))