Home >Backend Development >PHP Tutorial >Determine whether the string emailAddr is a legal email format_PHP tutorial
/**
* Determine whether the string emailAddr is a legal email format
* Mainly determine whether @ and . appear, and their positions
* @param emailAddr The entered email address
* @return true/ false.
*/
function emailCheck(emailAddr)
{
if((emailAddr == null) || (emailAddr.length < 2)) return false ;
// @ must appear and not be the first character.
var aPos = emailAddr.indexOf("@" ,1) ;
if(aPos < 0)
{
return false ;
}
// Appears after @, and does not follow immediately.
if(emailAddr.indexOf("." ,aPos+2) < 0)
{
return false ;
}
return true ;
}