checking for at least 18 years old

L

laredotornado

Hi,

Given select menus named birthMonth, birthDay, and birthYear, how do I
check if the user has selected values such that he/she is at least 18
years old?

Thanks, - Dave
 
T

Thomas 'PointedEars' Lahn

laredotornado said:
Given select menus named birthMonth, birthDay, and birthYear, how do I
check if the user has selected values such that he/she is at least 18
years old?

You can't.


PointedEars
 
E

Evertjan.

laredotornado wrote on 04 apr 2008 in comp.lang.javascript:
Given select menus named birthMonth, birthDay, and birthYear, how do I
check if the user has selected values such that he/she is at least 18
years old?

You cannot, she/he could be lying.

It is much easier to just ask:

"Are you at least 18 years old?"
 
J

Jeremy J Starcher

Hi,

Given select menus named birthMonth, birthDay, and birthYear, how do I
check if the user has selected values such that he/she is at least 18
years old?

Thanks, - Dave

Like the others said, you can't.

If you must, you can get the system date from Javascript and extract out
the day and month and compare those values, then compare the year.

Its not worth the effort, however. Any time I see one of those boxes I
just put my mouse over the 'year' select box and start scrolling down
till I know I'm in the clear. I suspect that most users will do
something similar.

Even if you could be 100% sure they would enter their actual birthday,
you *still* can't trust it. Unless you are going to get the time/date
from another source, the system clock can be changed. In less than a
dozen mouse clicks I can have my machine thinking its 2040.
 
L

Lasse Reichstein Nielsen

Jeremy J Starcher said:
Any time I see one of those boxes I
just put my mouse over the 'year' select box and start scrolling down
till I know I'm in the clear. I suspect that most users will do
something similar.

I always pick 1st of January 1970. I keep hoping some badly coded
application will choke on the zero value of the epoch :)
No luck yet, though.

/L
 
D

Dr J R Stockton

In comp.lang.javascript message <e41c7d94-5ad6-4f7d-bf24-3ec40abe6549@m4
4g2000hsc.googlegroups.com>, Fri, 4 Apr 2008 13:19:12, laredotornado
Given select menus named birthMonth, birthDay, and birthYear, how do I
check if the user has selected values such that he/she is at least 18
years old?

Others have failed to read that carefully. You are not asking about the
true age of the user, but about the age implied by the selection. if
that is a reasonable thing to use, it is also reasonable to assume that
the computer date is correctly set.

There may be an inevitable complication if either the current date or
the stated DoB is February 29th and the age is close to 18. You will
need to consider the legislation of the jurisdiction.

This will get an Object corresponding to the start of the current local
day :
D1 = new Date()
D1.setHours(0,0,0,0)

and D0 = new Date(birthYear+18, birthMonth-1, birthDay) gets the start
of the local 18th birthday. Compare them with (D0 >= D1). On second
thoughts, setHours is probably not needed.

That will deal correctly with Summer Time, unlike other possible
methods.

Probably you should validate the selected Y M D as being a good date, or
else control the birthDay menu to have the correct length for the
selected birthYear and birthMonth, in which case they should be placed
in the logical order rather than that favoured in the land of Mr
Frederick Flintstone.

If you are submitting the data, you can submit the local date as a
check.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
D

Dr J R Stockton

Sat said:
I always pick 1st of January 1970. I keep hoping some badly coded
application will choke on the zero value of the epoch :)
No luck yet, though.

You won't get a zero value if you do it in Denmark, AFAICs; you'll get
for JavaScript -36e5 and for C/UNIX -36e2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top