How to validate this date of birth from a form ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soulmasta
Forum Newbie
Posts: 17
Joined: Fri Aug 15, 2008 4:50 pm

How to validate this date of birth from a form ?

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

If you know it's in DD/MM/YY(YY) format then explode and checkdate are enough.
soulmasta
Forum Newbie
Posts: 17
Joined: Fri Aug 15, 2008 4:50 pm

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

Post by soulmasta »

thanks chiefs ;)
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post 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
Post Reply