Skip to content

Instantly share code, notes, and snippets.

@davatron5000
Created May 28, 2015 19:34
Show Gist options
  • Save davatron5000/4c036bd078c2f51ef2aa to your computer and use it in GitHub Desktop.
Save davatron5000/4c036bd078c2f51ef2aa to your computer and use it in GitHub Desktop.
HTML5 Validation on blur()
var inputs = document.querySelectorAll('input, textarea');
for(var i=0;i<inputs.length;i++) {
inputs[i].addEventListener('blur', function(){
if(!this.checkValidity()) {
this.classList.add('has-error');
} else {
this.classList.remove('has-error');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment