您的位置:首页 > Web前端 > JavaScript

CH6--正则表达式p110,重要,常用表格js提交验证,onblur验证精炼代码,光盘中有全部代码

2016-12-19 14:48 459 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>应用正则表达式对用户注册信息进行验证</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style></head>
<script src="js/check.js"></script>
<body>
<table width="765" height="229" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="229" colspan="2"><img src="images/bg_03.jpg" width="765" height="229" border="0" href="index.php" /></td>
</tr>
<tr>
<td width="565" height="364" align="center" valign="top">
<form name="reg_check" method="post" action="index_ok.php" onSubmit="return chkreg(reg_check,'all')">
<table width="550" height="270" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td height="38" colspan="3" valign="bottom"><img src="images/bg_05.jpg" width="543" height="30" /></td>
</tr>
<tr>
<td width="110" height="30"><div align="right">会员名:</div></td>
<td colspan="2" align="left"> <input type="text" name="recuser" size="20"  onBlur="chkreg(reg_check,0)">
<font color="#FF0000">*</font> 
<div id="check_recuser" style="color:#F1B000"></div></td>
</tr>

<tr>
<td height="30"><div align="right">详细联系地址:</div></td>
<td height="30" colspan="2" align="left"> <input type="text" name="address" size="50"  onBlur="chkreg(reg_check,1)">
<font color="#FF0000">*</font> 
<div id="check_address" style="color:#F1B000"></div></td>
</tr>
<tr>
<td height="30"><div align="right">邮政编码:</div></td>
<td height="30" colspan="2" align="left"> <input type="text" name="postalcode" size="20"  onBlur="chkreg(reg_check,2)"><div id="check_postalcode" style="color:#F1B000"></div></td>
</tr>
<tr>
<td height="30"><div align="right">QQ号码:</div></td>
<td height="30" colspan="2" align="left"> <input type="text" name="qq" size="20"  onBlur="chkreg(reg_check,3)">
<font color="#FF0000">*</font> 
<div id="check_qq" style="color:#F1B000"></div></td>
</tr>
<tr>
<td height="30"><div align="right">E-mail:</div></td>
<td height="30" colspan="2" align="left"> <input type="text" name="email" size="20" onBlur="chkreg(reg_check,4)">
<font color="#FF0000">*</font> <font color="#999999">请务必正确填写您的邮箱</font>
<div id="check_email" style="color:#F1B000"></div></td>
</tr>
<tr>
<td height="30" align="right">固定电话:</td>
<td height="30" colspan="2" align="left"> <input type="text" name="gtel" size="20"  onBlur="chkreg(reg_check,6)">
<font color="#FF0000">*</font> <font color="#999999"><div id="check_gtel" style="color:#F1B000"></div></font></td>
</tr>

<tr>
<td height="30"><div align="right">移动电话:</div></td>
<td height="30" colspan="2" align="left"> <input type="text" name="mtel" size="20"  onBlur="chkreg(reg_check,5)">
<font color="#FF0000">*</font> 
<div id="check_mtel" style="color:#F1B000"></div></td>
</tr>
<tr>
<td height="30"> </td>
<td width="100" height="30"><input type="image"  src="images/bg_09.jpg"></td>
<!--reset的应用;-->
<td width="340"><img src="images/bg_11.jpg" width="56" height="30" onClick="reg_check.reset()" style="cursor:hand"/></td>
</tr>
</table>
</form></td>
<td width="200" height="364"><img src="images/bg_07.jpg" width="200" height="364" /></td>
</tr>
<tr>
<td colspan="2"><img src="images/bg_08.jpg" width="765" height="101" /></td>
</tr>
</table>

</body>
</html>
function checkregtel(regtel){var str=regtel;var Expression=/^13(\d{9})$|^18(\d{9})$|^15(\d{9})$/;//*****var objExp=new RegExp(Expression);if(objExp.test(str)==true){return true;}else{return false;}}function checkregtels(regtels){var str=regtels;var Expression=/^(\d{3}-)(\d{8})$|^(\d{4}-)(\d{7})$|^(\d{4}-)(\d{8})$/;var objExp=new RegExp(Expression);if(objExp.test(str)==true){return true;}else{return false;}}function checkregemail(emails){var str=emails;//rer'33232@qq.co'm   这个为何可以通过验证;//rer'33232@q'q.com   这个为何不可以通过验证;var Expression=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;//???var objExp=new RegExp(Expression);if(objExp.test(str)==true){return true;}else{return false;}}function chkreg(form,label){if(label==0 || label=="all"){if(form.recuser.value==""){check_recuser.innerHTML="请输入会员名!";form.recuser.style.backgroundColor="#F1B000";return false;}else{check_recuser.innerHTML="";form.recuser.style.backgroundColor="#FFFFFF";}}if(label==1 || label=="all"){if(form.address.value==""){check_address.innerHTML="请输入联系地址!";form.address.style.backgroundColor="#F1B000";return false;}else{check_address.innerHTML="";form.address.style.backgroundColor="#FFFFFF";}}if(label==2 || label=="all"){if(form.postalcode.value==""){check_postalcode.innerHTML="请输入邮编!";form.postalcode.style.backgroundColor="#F1B000";return false;}else if(isNaN(form.postalcode.value)){//函数用于判断指定数字是否是非数字值check_postalcode.innerHTML="邮编由数字00组成!";form.postalcode.style.backgroundColor="#F1B000";return false;}else if(form.postalcode.value.length!=6){check_postalcode.innerHTML="邮编由6位数字组成!";form.postalcode.style.backgroundColor="#F1B000";return false;}else{check_postalcode.innerHTML="";form.postalcode.style.backgroundColor="#FFFFFF";}}if(label==3 || label=="all"){if(form.qq.value==""){check_qq.innerHTML="请输入QQ号码!";form.qq.style.backgroundColor="#F1B000";return false;}else if(isNaN(form.qq.value)){check_qq.innerHTML="QQ号由数字组成!";form.qq.style.backgroundColor="#F1B000";return false;}else{check_qq.innerHTML="";form.qq.style.backgroundColor="#FFFFFF";}}if(label==4 || label=="all"){if(form.email.value==""){check_email.innerHTML="请输入E-mail地址!";form.email.style.backgroundColor="#F1B000";return false;}else if(!checkregemail(form.email.value)){check_email.innerHTML="邮箱地址的格式不正确!";form.email.style.backgroundColor="#F1B000";return false;}else{check_email.innerHTML="";form.email.style.backgroundColor="#FFFFFF";}}if(label==5 || label=="all"){if(form.mtel.value==""){check_mtel.innerHTML="请输入电话号码!";form.mtel.style.backgroundColor="#F1B000";return false;}else if(!checkregtel(form.mtel.value)){check_mtel.innerHTML="电话号码的格式不正确!";form.mtel.style.backgroundColor="#F1B000";return false;}else if(isNaN(form.mtel.value)){check_mtel.innerHTML="电话号由数字组成!";form.mtel.style.backgroundColor="#F1B000";return false;}else{check_mtel.innerHTML="";form.mtel.style.backgroundColor="#FFFFFF";}}if(label==6 || label=="all"){if(form.gtel.value==""){check_gtel.innerHTML="请输入电话号码!";form.gtel.style.backgroundColor="#F1B000";return false;}else if(!checkregtels(form.gtel.value)){check_gtel.innerHTML="电话号码的格式不正确!";form.gtel.style.backgroundColor="#F1B000";return false;}else{check_gtel.innerHTML="";form.gtel.style.backgroundColor="#FFFFFF";}}}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: