How do I verify age using jQuery?

I need a simple age verification script.  I have the basics for it.

$('#frm-verify-age').submit(function() {
                  var
                        min_age = 18;
                        month = $('#frm-verify-month').val();
                        day = $('#frm-verify-day').val();
                        year = $('#frm-verify-year').val();
                        var theirDate = new Date((year + min_age), month, day);
                        var today = new Date;
                        if ( (today.getTime() - theirDate.getTime()) < 0) {
                              alert("You are too young to enter this site!");
                        }
                        else {
                              alert("You are old enough");
                        }
                        return false;
            });

<form action="#" method="post" name="frm-verify-age" id="frm-verify-age">
                        <fieldset class="first">
                              <p class="month">
                                    <label>Month</label>
                                    <input name="frm-verify-month" id="frm-verify-month" type="text" value="MM" />
                              </p>
                              <p class="day">
                                    <label>Day</label>
                                    <input name="frm-verify-day" id="frm-verify-day" type="text" value="DD" />
                              </p>
                              <p class="year last">
                                    <label>Year</label>
                                    <input name="frm-verify-year" id="frm-verify-year" type="text" value="YYYY" />
                              </p>
                        </fieldset>
                        <fieldset>
                              <p class="state last">
                                    <label>Year</label>
                                    <input name="frm-verify-state" id="frm-verify-state" type="text" value="Select" />
                              </p>
                        </fieldset>
                        <fieldset class="last">
                              <p class="submit">
                                    <label>Year</label>
                                    <input name="frm-verify-submit" id="frm-verify-submit" type="submit" value="" />
                              </p>
                        </fieldset>
                  </form>
aznprncriticAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mstrelanCommented:
does it work?
0
leakim971PluritechnicianCommented:
Use :


<script language="javascript">
	$(document).ready(function() {
		$('#frm-verify-age').submit(function() {
			var min_age = 18;
			month = $('#frm-verify-month').val();
			day = $('#frm-verify-day').val();
			year = $('#frm-verify-year').val();
			var theirDate = new Date(parseInt(year) + min_age, month-1, day);
			var today = new Date();
			if ( (today.getTime() - theirDate.getTime()) >= 0) {
				alert("You are old enough");
				return true;
			}
			alert("You are too young to enter this site!");
			return false;
		 });
	});
</script>

Open in new window

0
leakim971PluritechnicianCommented:
Integration :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" src="jquery.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$('#frm-verify-age').submit(function() {
			var min_age = 18;
			month = $('#frm-verify-month').val();
			day = $('#frm-verify-day').val();
			year = $('#frm-verify-year').val();
			var theirDate = new Date(parseInt(year) + min_age, month-1, day);
			var today = new Date();
			if ( (today.getTime() - theirDate.getTime()) >= 0) {
				alert("You are old enough");
				return true;
			}
			alert("You are too young to enter this site!");
			return false;
		 });
	});
</script>
</head>
<body>
<form action="#" method="post" name="frm-verify-age" id="frm-verify-age">
    <fieldset class="first">
    <p class="month">
        <label>Month</label>
        <input name="frm-verify-month" id="frm-verify-month" type="text" value="MM" />
    </p>
    <p class="day">
        <label>Day</label>
        <input name="frm-verify-day" id="frm-verify-day" type="text" value="DD" />
    </p>
    <p class="year last">
        <label>Year</label>
        <input name="frm-verify-year" id="frm-verify-year" type="text" value="YYYY" />
    </p>
    </fieldset>
    <fieldset>
    <p class="state last">
        <label>Year</label>
        <input name="frm-verify-state" id="frm-verify-state" type="text" value="Select" />
    </p>
    </fieldset>
    <fieldset class="last">
        <p class="submit">
        <label>Year</label>
    <input name="frm-verify-submit" id="frm-verify-submit" type="submit" value="valid" />
    </p>
    </fieldset>
</form>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aznprncriticAuthor Commented:
nice, was missing the -1 for month
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.