Well, if you say it like that then it is a bit confusing. lol
It would probably be better to add more different checks with different messages.
Code:
function dobvali()
{
var currentdate = new Date();
var yearonly = currentdate.getFullYear();
var usrdob = document.getElementById('dob').value;
var res = yearonly-usrdob;
if (!usrdob) // if the input is empty
alert('fill this');
else if (isNaN(usrdob)) // if the input does not contain a number
alert('invalid input');
else if (usrdob < yearonly-100 || usrdob > yearonly) // if date of birth is in the future or more than 100 years ago
alert('invalid year');
else if (res < 20) // if age is less than 20
alert('not enough');
else
alert('welcome');
}
Bookmarks