当前位置:编程学习 > JS >>

js电话 邮箱地址验证程序

网页特效电话 邮箱地址验证程序
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.zzzyk.com/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />

<title>网页特效电话 邮箱地址验证程序</title>
<script language="网页特效">
 function c(obj){ return document.getelementbyid(obj);}
 
 if(c('phone').value!="")
    {
        var tel=/^(+)*(d{0,2}-)*((d{3}|d{4})-)*(d{8}|d{7})$/;
        var phone=/^(+)*(d{0,2}-)*0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/; 
        if(!phone.test(c('phone').value)&&!tel.test(c('phone').value))
        {
            c('errorphone').innerhtml="电话格式错误";
             c('phone').focus();
            return false;
        }
   
    }
    c('erroremail').innerhtml="";
    if(c('email').value!="")
    {
        var filter=/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/; 
        if(!filter.test(c('email').value))
        {
            c('erroremail').innerhtml="邮箱格式错误";
            c('email').focus();
            return false;
        }   
    }    
</script>

</head>

<body>
</body>
</html>

补充:网页制作,js教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,