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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:21:44
Original
1544 people have browsed it

/**
 * 判断字符串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 ;
}


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template