Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date of birth validation for under 14

Status
Not open for further replies.
Mar 20, 2003
103
0
0
AU
Hi..

I am creating a form and I need a script to validate the date of birth entered to check whether they are under 14.

Does anyone know how to do it?
 
ask for their birthdate, then compare it like this:

Code:
var msIn14Years = 1000 * 60 * 60 * 365 * 14;

var dAge = new Date('06/24/1980');
var dToday = new Date();

if (dToday - dAge >= msIn14Years ) {
    alert('you are at least 14');
} else {
    alert('you are NOT at least 14');
}

i haven't tested this code.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
You really need to do this comparison server-side... Doing it client-side will get any [under 14] script kiddie the ability to bypass it fairly easily.

Mind you, I guess they could just lie about their age anyway, so might not be such a big deal.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top