初学JSP不久.. 现在有个题目是关于EMail的合法验证比如说([email protected])...还真不知道怎么写..
麻烦大家给我代码..谢谢.. .

解决方案 »

  1.   

    最简单的验证就是indexof("@")是否为-1用户名的话可以查表或者设计的数据库中为主键
      

  2.   

    验证Email地址:“^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$”
    用户有没有被占用 就必须查找数据库了
      

  3.   

    /*-----------------------------------
    Function Detail : 判断用户输入的电子信箱是否符合格式
    Return          : 符合格式   : true
                      不符合格式 : false
    */
    function checkIsEmailNumber(strWord)
    {
    var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    if(reg.test(strWord))
    return true;
    else
    return false;
    }
    使用时就只要checkIsEmailNumber("你的邮箱地址");如果正确就是true,不正确就是false
      

  4.   

    <script>
    /*-----------------------------------
    Function Detail : 判断用户输入的电子信箱是否符合格式
    Return          : 符合格式   : true
                      不符合格式 : false
    */
    function checkIsEmailNumber(strWord)
    {
    var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    if(reg.test(strWord))
    alert("你的邮箱地址正确");
    else
    alert("你的邮箱地址不正确");
    }
    </script>
    你的邮箱地址:<input type=text name=mail>
    <input type=button value=检查 onclick=checkIsEmailNumber("mail.value")>