Last active
August 29, 2015 14:01
-
-
Save duccoder/93f79aed5c87a2f8b262 to your computer and use it in GitHub Desktop.
Valid Email with JS
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
<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