Skip to content

Instantly share code, notes, and snippets.

@duccoder
Last active August 29, 2015 14:01
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 duccoder/93f79aed5c87a2f8b262 to your computer and use it in GitHub Desktop.
Save duccoder/93f79aed5c87a2f8b262 to your computer and use it in GitHub Desktop.
Valid Email with JS
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<form>
<label for="regExField">Email: </label>
<input id="regExField" type="text">
<span id="messageExField"></span>
</form>
<script type="text/javascript">
$(document).ready(function () {
function checkEmailValid(str) {
var regEx = /^.{1,}@.{2,}\..{2,}/;
return str.match(regEx);
}
$( "#regExField" ).keyup(function() {
var valText = $(this).val();
if(checkEmailValid(valText))
{
$('#messageExField').html('Email valid')
} else {
$('#messageExField').html('Email not valid')
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment