表格:签入JavaScript

I have 2 fields, the first field is named name and the second dateofbirth. I would like to improve the validation mostly on my field dateofbirth. I would like to use a simple code for beginner.

the rule, the user can enter a date bigger than -> 01-01-1900, if the date is smaller, an error message must appear.

function validation()
{
    var name = document.getElementById('name').value;
    var dateofbirth = document.getElementById('dateofbirth').value;

    if(name == ""){
        document.getElementById('nameError').innerHTML = " ** the name field is empty ! ";
         return false;
    }

    if(name.length < 2){
        document.getElementById('nameError').innerHTML = " ** min 2 characters ! ";
        return false;
    }

    if(dateofbirth == ""){
        document.getElementById('dateofbirthError').innerHTML = " ** the date field is empty ! ";
        return false;
    }
}
<form action="#" onsubmit="return validation()" >
<br>
<label>Name : </label>
<br>
<input type="text" name="name" id="name">
<br>
<span id="nameError"></span>
<br>
<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>
评论