Created
March 23, 2015 23:04
-
-
Save KruegerDesigns/21fddb770406ed4bce80 to your computer and use it in GitHub Desktop.
Simple and lightweight jQuery email validation.
This file contains hidden or 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
<!-- 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