Skip to content

Instantly share code, notes, and snippets.

@KruegerDesigns
Created March 23, 2015 23:04
Show Gist options
  • Save KruegerDesigns/21fddb770406ed4bce80 to your computer and use it in GitHub Desktop.
Save KruegerDesigns/21fddb770406ed4bce80 to your computer and use it in GitHub Desktop.
Simple and lightweight jQuery email validation.
<!-- Add the styles below to your CSS file -->
<style>
input.email-error {
color: #C24C4C;
}
</style>
<!-- Add the jQuery below to your Javacript file -->
<script>
$(document).ready( function(){
// Change 'button' to 'input' if needed
$('input[type=email]').on("keyup", function() {
var emailTest = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!emailTest.test(this.value)) {
$(this).addClass("email-error");
$("button[type=submit]").attr('disabled','disabled');
} else {
$(this).removeClass("email-error");
$("button[type=submit]").removeAttr('disabled');
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment