Hello All,
In one of my project I have to enter birth date.
BirthDateValidation function validates the BirthDate based on two conditions.
- The date should be less than or equal to the current date
- The date should be greater than current date and the difference between the current date and the date 100 years back.
So, right down the following code in your java script.
function BirthDateValidation()
{
var val=document.getElementById('birthdate').value;
var splits = val.split("/");
var dt = new Date(splits[1] + "/" + splits[0] + "/" + splits[2]);
var dtToday = new Date();
var pastDate = new Date(Date.parse(dtToday.getMonth()+"/"+dtToday.getDate()+"/"+parseInt(dtToday.getFullYear()-100)));
if (dt < pastDate || dt >= dtToday) {
alert("Birth Date can not be greatear than current Date"); }
else {
alert("valid BirthDate"); }
}
Write your Html code.
form name="validation" id="validation" method="post"
input name="birthdate" id="birthdate" type="text"
input name="btnsubmit" onClick="BirthDateValidation();" type="submit"
(formate dd/mm/yyyy
Simple you will get the right birth date. Better use calender instead of write birth date in textbox directly.
No comments:
Post a Comment