JavaScript: Age Validation Form

Published on

This form validates the date selected by the user is valid and that the user is at least the age of 18. (Note that it does not dynamically adjust the day select list based on the month and year selected.) HTML <form id=”age-validation-form” class=”form-inline” method=”POST”> <div class=”form-group”> <select name=”dob_month” id=”dob_month” class=”required form-control”> <option value=””>Month</option> <option … Continue reading JavaScript: Age Validation Form

JavaScript: Age Validator

Published on

function isOfAge(year, month, day, age) { age = age || 18; var mydate = new Date(); mydate.setFullYear(year, month-1, day); var currdate = new Date(); currdate.setFullYear(currdate.getFullYear() – age); if ((currdate – mydate) < 0) { return false; } return true; } References: Validate Age | CSS-Tricks