Using onblur to set custom validation using setCustomValidity()

I’m trying to make custom validation using setCustomValidity(), it’s work only when user submit the form. How can i set it on onblur , validate the textbox while user enter the value ? any help would be appreciated.

input type="text" name="YEAR" id="YEARMAKE" value="" required="true" oninput="validate(this)" />

function validate(input) 
{
    var yearlength = input.value;

    if (yearlength.length < 4) {
        input.setCustomValidity('The year must have 4 digits');
        return false;
    } else {
        input.setCustomValidity('');
        return true;
    }
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.