Page 1 of 1

How to validate this date of birth from a form ?

Posted: Wed Oct 22, 2008 4:00 pm
by soulmasta
Hello chiefs,

On a form, i have an input box :

Code: Select all

 
<form>
 
<input name="birthdate" value="">
 
</form>
 
This input box is there for users to set their date of birth .

I want the users to give into that input box their date of birth in such a way : DAY/MONTH/YEAR dd/mm/yy
and so am expecting from every user to write something like this : 20/12/1960 .

Ok till here ;)

Now i want to validate the day of birth in this form of dd/mm/yy !

But how to ?

I store the input into one variable $thedate.. par example,

Code: Select all

 
$thedate = $_POST['birthdate'];
 
Now how we can validate the index of this variable correctly ?

Thanks

Re: How to validate this date of birth from a form ?

Posted: Wed Oct 22, 2008 4:12 pm
by VladSun

Re: How to validate this date of birth from a form ?

Posted: Wed Oct 22, 2008 4:16 pm
by califdon
Probably the simplest and surest way is to use code that has already been written and tested. Try http://www.phpclasses.org/browse/package/1190.html.

Re: How to validate this date of birth from a form ?

Posted: Wed Oct 22, 2008 4:38 pm
by requinix
If you know it's in DD/MM/YY(YY) format then explode and checkdate are enough.

Re: How to validate this date of birth from a form ?

Posted: Wed Oct 22, 2008 5:51 pm
by soulmasta
thanks chiefs ;)

Re: How to validate this date of birth from a form ?

Posted: Thu Oct 23, 2008 2:42 am
by aceconcepts
An alternative method would be to use three input elements: select list for day, select list for month and text box for year (using maxlength).

Just a thought :D