you are in: codestackercodes [RSS]simple date validation

simple date validation Delicious Email

show/hide lines
   1  function dateValidation() {
   2  
   3  	var obj = document.getElementById("my_field"); // my_field: 12/12/2011
   4  	var day = obj.value.split("/")[0];
   5  
   6  	var month = obj.value.split("/")[1];
   7  	var year = obj.value.split("/")[2];
   8  
   9  	if ((day<1 || day >31) || (month<1&&month>12)&&(year.length != 4)) {
  10  		alert("Invalid format");
  11  		return false;
  12  	} else {
  13  
  14  		var dt = new Date(year, month-1, day);
  15  		var today = new Date();
  16  
  17  		if((dt.getDate() != day) || (dt.getMonth() != month-1) || (dt.getFullYear()!=year) || (dt>today)) {
  18  			alert("Invalid date");
  19  			return false;
  20  		}
  21  	}
  22  }
created by leozera — 16 November 2011 — get a short url — tags: date javascript embed

Comments



We dont send spam :)

If checked, it's highlights your comment
simple_captcha.jpg
Are you a human? Type the code from the image