Validating a year from form input
Posted: Sat Jan 20, 2007 11:39 am
I am trying to validate a year that a user inputs from a form. The format MUST be in "2007" format so I came up with the code here. But it is not working.
Code: Select all
//Check experation date
if ("$date_override" == '1')
{
if(trim("$pn_duesexdate") =='' || strlen(trim("$pn_duesexdate")) == 4)
{
$error_msg.="<li>The experation year is invalid.</li>";
$error_12 = ' class="formerror"';
}else{
// now check if year is a valid format
if(!ereg("([0-9]{4})", "$pn_duesexdate"))
{
$error_msg.="<li>The experation year is invalid.</li>";
$error_12 = ' class="formerror"';
}
}
}