Skip to content

Instantly share code, notes, and snippets.

@afelicioni
Created March 14, 2016 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afelicioni/d02341aae2b0cf0dc573 to your computer and use it in GitHub Desktop.
Save afelicioni/d02341aae2b0cf0dc573 to your computer and use it in GitHub Desktop.
custom validation email input message
[].forEach.call( document.querySelectorAll('[type="email"]'), function(emailElement) {
emailElement.addEventListener('invalid', function() {
var message = this.value + 'is not a valid email address';
emailElement.setCustomValidity(message)
}, false);
emailElement.addEventListener('input', function() {
try{emailElement.setCustomValidity('')}catch(e){}
}, false);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment