Created
April 10, 2014 14:31
-
-
Save kalinchernev/10388605 to your computer and use it in GitHub Desktop.
Email validators for javascript
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
/** | |
* Validates if the input for email field matches requirements and if it's a valid email | |
* @returns {void} | |
*/ | |
function validateEmail() { | |
var inputValue; | |
// clear previous | |
jQuery(".reg-validate-email").remove(); | |
inputValue = jQuery(this).val(); | |
if ( inputValue.length > 0 && validateEmailRegEx(inputValue) ) { | |
jQuery(this).after("<span class='reg-validate-email alert alert-success'>Email is good!<i class='icon-fix icon-ok'></i></span>"); | |
} else { | |
jQuery(this).after("<span class='reg-validate-email alert alert-error'>Email is not good!<i class='icon-fix icon-exclamation-sign'></i></span>"); | |
} | |
} | |
/** | |
* Helper | |
* @returns {void} | |
*/ | |
function validateEmailRegEx(email) { | |
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
return re.test(email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment