Validate a date of birth using jQuery in jQuery
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

Validating dates of birth are a common task on websites that have content available only for users 18+ years old. Using jQuery, this is very easy to do, as shown in the following example:

$("#lda-form").submit(function(){
	var day = $("#day").val();
	var month = $("#month").val();
	var year = $("#year").val();
	var 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){
		alert("Sorry, only persons over the age of " + age + " may enter this site");
		return false;
	}
	return true;
});

Source

You may want to check :

  1. Simple jQuery Accordion
  2. Load jQuery only if it’s not already loaded
  3. Display the Current Date
  4. Display author, tags, number of comments and date published
  5. get custom fields easier hack

Post a Comment

Your email is never shared. Required fields are marked *

*
*