Last active
August 29, 2015 13:57
-
-
Save gchriswill/9717605 to your computer and use it in GitHub Desktop.
This is a validation formula or method condition to validate an email string from an input or text field with JavaScript. (No RegEx, just pure JavaScript)
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
//Save the value of the field into a variable | |
var emailValue = emailField.getValue(); | |
/* This formula or method condition in five easy steps | |
* | |
* 1- First searches for an "@" in the string | |
* 2- Then it checks for more than one "@" | |
* 3- Then checks if the subdomain area is less than 4 characters | |
* 4- Then checks if the position of the last "." is less than 3 spaces after the "@" | |
* 5- Then checks if there are two or less characters after the last "." | |
*/ | |
if ( ( emailValue.search("@") == -1 ) || ( emailValue.indexOf("@") !== emailValue.lastIndexOf("@") ) || emailValue.indexOf("@") < 4 || emailValue.lastIndexOf(".") < emailValue.indexOf("@") + 3 || emailValue.lastIndexOf(".") + 2 >= emailValue.length ) | |
{ | |
alert("Please enter a valid email"); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@j-acevedo ,
This is the email format validation formula or method condition that you're looking for...