How can we add validation in date of birth input field . I create one input field of date of birth and in this field it's show like that 01/07/1997. But I want to get when date of birth enter in field it's showing like that, Xx/xx/1997. Only year want to show date and months not show.
I tried but not work. Anyone please help me out to resolve this issue.
Thanks in advance.
Try this and change the code as per your requirement changes- I have updated here you just copy paste this code into following URL-http://jsfiddle.net/h9f46/84/
function validate(date){
var eighteenYearsAgo = moment().subtract(18, "years");
var birthday = moment(date);
var dateVar = new Date(birthday);
if (!birthday.isValid()) {
return "invalid date";
}
else if (eighteenYearsAgo.isAfter(birthday)) {
return "**/**/"+ dateVar.getFullYear().toString();
}
else {
return "sorry, no";
}
}
jsprint(validate, "12/10/2000");