Skip to content

Instantly share code, notes, and snippets.

@johandouma
Last active April 14, 2016 03:43
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 johandouma/ded96df8e0b710b3aac7c08b4464abeb to your computer and use it in GitHub Desktop.
Save johandouma/ded96df8e0b710b3aac7c08b4464abeb to your computer and use it in GitHub Desktop.
Simplest validation for Safari and <=IE9
//// Validation
if (typeof document.createElement('input').checkValidity === 'function') {
$('form').submit(function (e) {
if (!this.checkValidity()) {
e.preventDefault();
alert('Some fields are invalid. Please check your form again. ');
}
});
} else {
$('form').submit(function (e) {
errors = $(this)
.find("input:not([type=radio]):not([type=checkbox]), select, textarea")
.filter("[required]")
.filter(function() { return ($(this).val() ? false : true); });
if (errors.length > 0) {
e.preventDefault();
alert('Some fields are invalid. Please check your form again.');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment