My knowledge of regexregular expressions is not that good. That's why I check the general syntax with a simple regexregular expression first, and check more specific options with other functions afterwards. This may not be not the best technical solution, but this way I'm way more flexible and faster.
The most common errors I've come across are spaces (especially at the beginngingbeginning and end) and occasionally a double dot.
function check_email(val){
if(!val.match(/\S+@\S+\.\S+/)){ // Jaymon's / Squirtle's solution
// doDo something
return false;
}
if( val.indexOf(' ')!=-1 || val.indexOf('..')!=-1){
// doDo something
return false;
}
return true;
}
check_email('check@thiscom'); // returnsReturns false
check_email('[email protected]'); // returnsReturns false
check_email(' [email protected]'); // returnsReturns false
check_email('[email protected]'); // returnsReturns true