Skip to content

Instantly share code, notes, and snippets.

@MaruscaGabriel
Created February 22, 2018 12:44
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 MaruscaGabriel/ee2efdf994f63caad3cf9e1327a5ef9a to your computer and use it in GitHub Desktop.
Save MaruscaGabriel/ee2efdf994f63caad3cf9e1327a5ef9a to your computer and use it in GitHub Desktop.
Email Validation Using jQuery
jQuery(document).ready(function(e) {
jQuery('.submit-button-class').click(function() {
var valEmail = jQuery('.email-field-class').val();
if (jQuery.trim(valEmail).length == 0) {
alert('Please enter valid email address');
e.preventDefault();
}
if (validateEmail(valEmail)) {
}
else {
alert('Invalid Email Address');
e.preventDefault();
}
});
});
function validateEmail(valEmail) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test(valEmail)) {
return true;
}
else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment