I know the subject exists on StackOverFlow as below, but I don't understand.
How to validate date with format "mm/dd/yyyy" in JavaScript?
My goal is that when the date of birth is false, an error message appears.
I want to understand how to valide the year for example ?
If the user enters 1000-01-01 or 3000-01-01, I would like to get an error message.
Thank you for your help
function validation(){
var dateofbirth = document.getElementById('dateofbirth').value;
if(dateofbirth == ""){
document.getElementById('dateofbirthError').innerHTML = "Empty";
return false;
}
}
<form action="#" onsubmit="return isValidDate()" >
<label>Date of birth : </label>
<br>
<input type="date" name="dateofbirth" id="dateofbirth">
<br>
<span id="dateofbirthError"></span>
<br>
<input type="submit" value="ok">
</form>