Home >php教程 >php手册 >判断字符串emailAddr是否为合法的email格式

判断字符串emailAddr是否为合法的email格式

WBOY
WBOYOriginal
2016-06-13 10:21:441518browse

/**
 * 判断字符串emailAddr是否为合法的email格式
 * 主要判断@及.是否出现,以及两者的位置
 * @param emailAddr 输入的email地址
 * @return true/false。
 */

function emailCheck(emailAddr)
{
    if((emailAddr == null) || (emailAddr.length

    // 需出现@,且不在首字符.
    var aPos = emailAddr.indexOf("@" ,1) ;

    if(aPos     {
        return false ;
    }

    // @后出现.,且不紧跟其后.
    if(emailAddr.indexOf("." ,aPos+2)     {
        return false ;
    }

    return true ;
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn