jsp js正则表达式用法

<%@ 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 不能相同
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值