My HTMl form has an email input with a required attribute:

<input type="email" name="email" id="email" required>

On form submit, an alert is displayed when the user does not enter the correct format.

Is there a way that when the input loses focus, the alert is still triggered when the user does not follow the correct format?

1 Answers

0
Jun Dolor On

On Vanilla JavaScript, I used the checkValidity() and validationMessage on the DOM. Here is the code:

email.addEventListener("blur", function(){
        if(!email.checkValidity()){
            document.getElementById("errEmail").innerHTML = email.validationMessage;
        }
})