首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

正则表达式 哪里出有关问题了为什么没有反应

2012-04-24 
正则表达式 哪里出问题了为什么没有反应?htmlheadmeta http-equivContent-Type contenttext/htm

正则表达式 哪里出问题了为什么没有反应?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>验证表单数据</title>
<script type="text/javascript">
function showshow()
{
alert("sdf");
if(/[\u4E00-\u9FA5]+/.test($("chinaName").value)!=true)
{
alert("真实名字必须为中文!!");
$("chinaName").select();
$("chinaName").focus():
return false;
}
if(/[a-zA-Z]+/.test($("englishName").value)!=true)
{
alert("英文名字不合法!");
$("englishName").select();
$("englishName").focus();
return false;
}
if(/[a-zA-Z0-9_]+/.test($("password1").value)!=true||$("").value.length-1<5)
{
alert("密码不合法!!");
$("password1").select();
$("password1").focus();
return false;
}
if($("password1").value!=$("password2").value)
{
alert("两次密码不一致!!");
$("password2").select();
$("password2").focus();
return false;
}
if(/^[a-zA-Z]+\@[a-zA-Z0-9]+\.[a-z]{2,3}/.test($("email").value)!=true)
{
alert("邮箱地址不合法!!");
$("email").select();
$("email").focus();
return false;
}
if(/\d{5,9}/.test($("qq").value)!=true)
{
alert("QQ不合法!!");
$("qq").select();
$("qq").focus();
return false;
}
if(/(\d{15})|(\d{17}[a-z0-9])/.test($("cardId").value)!=true)
{
alert("身份证不合法!!");
$("cardId").select();
$("cardId").focus();
return false;
}
if(/([2-9][0-9])|100/.test($("age").value)!=true)
{
alert("年龄不合法!!");
$("age").select();
$("age").focus();
return false;
}
if(/^(\d{3,4})-\d{7}/.test($("phone").value)!=true)
{
alert("座机电话不合法!!");
$("phone").select();
$("phone").focus();
return false;
}
if(/\d{11}/.test($("mobile").value)!=true)
{
alert("手机号码不合法!!");
$("mobile").select();
$("mobile").focus();
return false;
}
if(/\d+\.\d{2}$/.test($("salary").value)!=true)
{
alert("工资输入不合法!!");
$("salary").select();
$("salary").focus();
return false;
}
if(/\d{6}/.test($("zip").value)!=true)
{
alert("邮政编码不合法!!");
$("zip").select();
$("zip").focus();
return false;
}
if(/.+/.test($("address").value)!=true)
{
alert("家庭地址不能为空!!");
$("address").select();
$("address").focus();
return false;
}
alert("sdf");
return true;
}

function $(id)
{
alert("sdf");
return document.getElementById(id);
}
  alert($("chinaName").innerHTML);
</script>




 <style type="text/css">
 body,td{font:normal 12px Verdana;color:#333333}
 input,textarea,select,td{font:normal 12px Verdana;color:#333333;border:1px solid #999999;background:#ffffff}
 table{border-collapse:collapse;}
 td{padding:3px}
 input{height:20;}
 textarea{width:80%;height:50px;overfmin:auto;}
 form{display:inline}
 </style>
</head>

<body>
 <table width="665" align="center">


 <caption align="center">使用正则表达式验证表单数据</caption>
  <form name="form1" method="post" onSubmit="return showshow();">
  <tr>
  <td width="124">真实姓名:</td>
  <td width="368"><input name="chinaName" id="chinaName" dataType="Chinese">
  *必须为中文</td>
  </tr>
  <tr>
  <td>英文名:</td><td><input name="englishName" id="englishName">
  *必须由英文大小写字母组成</td>
  </tr>
  <tr>
  <td>密码:</td><td><input name="password1" type="password" id="password1">
  *由大小写字母、数字、下划线构成的6位以上的 密码</td>
  </tr>
  <tr>
  <td>重复:</td><td><input name="password2" type="password" id="password2">
  *第二次输入的密码和第一次输入的一致</td>
  </tr>
  <tr>
  <td>邮箱:</td><td><input name="email" id="email" >
  *必须按照email的规范</td>
  </tr>
  <tr>
  <td>QQ:</td><td><input name="qq" id="qq">
  *由数字组成的5-9位数字</td>
  </tr>
  <tr>
  <td>身份证:</td><td><input name="cardId" id="cardId">
  *有15位和18位两种</td>
  </tr>
  <tr>
  <td>年龄:</td><td><input name="age" id="age">
  *为整型数字,并且是20-100之间</td>
  </tr>
  <tr>
  <td>电话:</td><td><input name="phone" id="phone">
  *座机号码</td>
  </tr>
  <tr>
  <td>手机:</td><td><input name="mobile" id="mobile">
  *手机号码</td>
  </tr>
  <tr>
  <td>月工资:</td><td><input name="salary" id="salary">
  *为带小数点数</td>
  </tr>
  <tr>
  <td>邮政编码:</td><td><input name="zip" id="zip">
  *由数字组成的6位数字</td>
  </tr>
  <tr>
  <td>家庭住址:</td><td><input name="address" id="address">
  *不能为空</td>
  </tr>
  <tr>
  <td colspan="2" align="center">
  <input type="submit" value="提交验证" />
<input type="reset" value="取 消" /> </td>
  </tr>
  </form>
 </table>
</body>
</html>


[解决办法]
alert("真实名字必须为中文!!");
$("chinaName").select();
$("chinaName").focus():
return false;

分号

热点排行