0

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?

Jun Dolor
  • 609
  • 2
  • 11
  • 25

1 Answers1

0

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;
        }
})
Jun Dolor
  • 609
  • 2
  • 11
  • 25