Page 1 of 1

function checkdate accepting character value?????

Posted: Tue Sep 22, 2009 4:29 am
by om.bitsian
Hello friends
i am validating date field......it is accepting character value in my form
$BIRTH_DATE=($_POST['BIRTH_DATE']);
$BIRTH_MONTH=($_POST['BIRTH_MONTH']);
$BIRTH_YEAR=($_POST['BIRTH_YEAR']);
$date_birth = $BIRTH_YEAR."/".$BIRTH_MONTH."/".$BIRTH_DATE;
if(!checkdate($BIRTH_MONTH,$BIRTH_DATE,$BIRTH_YEAR))
{
die ('ERROR: Enter a valid birth date, the format is yyyy/mm/dd');
}


when i am entring 200h/1g/2f ..........the form is accepting even this value
out put is:
current date: 2009/09/22
birth date: 19809/2UTC/309

please help me to validate it properly

Re: function checkdate accepting character value?????

Posted: Tue Sep 22, 2009 7:26 am
by Mark Baker
Use ctypeto validate your day, month and year values before calling checkdate().

And use selection lists in your form rather than text boxes... that way, you have more control over the day, month and year values that can be posted by normal users.... still validate with ctype and checkdate on the server though.