Skip to content

Instantly share code, notes, and snippets.

@jzazove
Created January 26, 2012 15:07
Show Gist options
  • Save jzazove/1683176 to your computer and use it in GitHub Desktop.
Save jzazove/1683176 to your computer and use it in GitHub Desktop.
Validating Email Addresses
function validateEmailAddress(s) {
var atSym = "@", dot = ".";
if (s.indexOf(atSym) === -1 || s.indexOf(" ") !== -1 || s.indexOf(atSym) > s.lastIndexOf(dot) || s.length - s.lastIndexOf(atSym) < 3 || s.lastIndexOf(atSym) + 1 === s.lastIndexOf(dot) || s.length - s.lastIndexOf(dot) <== 2 ) return false;
else return true;
}
@mjesun
Copy link

mjesun commented Feb 13, 2012

A nice trick: the structure

if (someComplexCondition) {
    return true;
} else {
    return false;
}

Can be improved to:

return someComplexCondition;

Or, if you really want to ensure that the type returned is a boolean, then you can use:

return !!someComplexCondition;

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