Skip to content

Instantly share code, notes, and snippets.

@gchriswill
Last active August 29, 2015 13:57
Show Gist options
  • Save gchriswill/9717605 to your computer and use it in GitHub Desktop.
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)
//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");
};
@gchriswill
Copy link
Author

@j-acevedo ,

This is the email format validation formula or method condition that you're looking for...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment