<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>注册</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
function check(){
var name=document.getElementById("nameid");
var IDcard=document.getElementById("IDcardid");
var Email=document.getElementById("Emailid");
var qq=document.getElementById("qqid");
var phone=document.getElementById("phoneid");
var WeChat=document.getElementById("WeChatid");
if(!/^[\u4e00-\u9fa5],{0,}$/.test(name.value))
{
alert("姓名请输入汉字!");
return false;
}
else if(!/^\d{15}|\d{}18$/.test(IDcard.value))
{
alert("请输入正确的身份证号!");
return false;
}
else if(!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(Email.value))
{
alert("请输入正确的邮箱!");
return false;
}
else if(!/^[1-9]\d{4,10}$/.test(qq.value))
{
alert("请输入正确的qq号码!");
return false;
}
else if(!/^1[3456789]\d{9}$/.test(phone.value))
{
alert("请输入正确的手机号码!");
return false;
}
else
return true;
}
</script>
</head>
<body>
<form οnsubmit="return check()">
<table>
<tr><td>姓名:</td>
<td><input type="text" name="name" id="nameid"/></td>
</tr>
<tr><td>身份证号:</td>
<td><input type="text" name="IDcard" id="IDcardid"/></td>
</tr>
<tr><td>邮箱:</td>
<td><input type="text" name="Email" id="Emailid"/></td>
</tr>
<tr><td>QQ号:</td>
<td><input type="text" name="qq" id="qqid"/></td>
</tr>
<tr><td>电话:</td>
<td><input type="text" name="phone" id="phoneid"/></td>
</tr>
<tr><td>微信:</td>
<td><input type="text" name="WeChatid"/></td>
</tr>
<tr>
<td><input type="submit" value="确定"/></td>
</tr>
</table>
</form>
</body>
</html>
需要注意的是name 和 id 不能相同
jsp js正则表达式用法
最新推荐文章于 2021-04-10 05:36:06 发布