Created
February 22, 2018 12:44
-
-
Save MaruscaGabriel/ee2efdf994f63caad3cf9e1327a5ef9a to your computer and use it in GitHub Desktop.
Email Validation Using jQuery
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
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