javascript 电话,QQ,手机,身份证号,邮箱地址,邮政 正则表达式验证代码

来源:互联网 发布:魔域名剑客之墓怎么打 编辑:程序博客网 时间:2024/04/28 07:34
-
-
javascript教程 电话,QQ,手机,身份证号,邮箱地址,邮政 正则表达式验证代码
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript 电话,QQ,手机,身份证号,邮箱地址,邮政 正则表达式验证代码</title>
<script language="javascript">
function $(id)
{
 return document.getElementById(id);
}
function checkidcard(idcard) {
 idcard = trim(idcard);
 len = mb_strlen(idcard);
 if(len == 18 && preg_match(/^d{17}[dX]$/i, idcard)) {
  return true;
 }
 return dalert('身份证号码不合法!请重新填写', $('form1').idcard);
}


function checktel(tel1, tel2, tel3, telname) {
 if(!preg_match(/^d{2,4}$/, tel1) || !preg_match(/^d{5,10}$/, tel2) || (tel3 && tel3 != '分机号码' && !preg_match(/^d{1,5}$/, tel3))) {
  return dalert(telname + ' 不合法!请重新填写', $('form1').tel1);
 }
 return true;
}


function checkqq(qq) {
 if(!(preg_match(/^([0-9]+)$/, qq) && mb_strlen(qq) >= 5 && mb_strlen(qq) <= 12)) {
  return dalert('QQ 号码不合法!请重新填写', $('form1').qq);
 }
 return true;
}


function checkmobile(mobile) {
 if(!preg_match(/^1(3|5)d{9}$/, mobile)) {
  return dalert('手机号码不合法!请重新填写', $('form1').mobile);
 }
 return true;
}


function checkpostcode(postcode) {
 if(!preg_match(/^d{6}$/, postcode)) {
  return dalert('邮政编码不合法!请重新填写', $('form1').postcode);
 }
 return true;
}
</script>
</head>


<body>
</body>
</html>


更多详细内容请查看:http://www.111cn.net/wy/99/32959.htm
原创粉丝点击