Last active
April 14, 2016 03:43
-
-
Save johandouma/ded96df8e0b710b3aac7c08b4464abeb to your computer and use it in GitHub Desktop.
Simplest validation for Safari and <=IE9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// 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