DDR爱好者之家 Design By 杰米

源码如下所示:

 
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		用户名:<input type="text"name = "user" id="user"/>
			 <span id="userSpan" style="font-size: 16pt;"></span>
		<br />
		密码:<input type="text"name = "pwd" id="pwd"/>
			<span id="pwdSpan" style="font-size: 16pt;"></span>
		<br />
		确认密码:<input type="text"name = "pwd2" id="pwd2"/>
		<span id="pwd2Span" style="font-size: 16pt;"></span>
		<br />
		邮箱:<input type="text"name = "email" id="email"/>
		<span id="emailSpan" style="font-size: 16pt;"></span>
		<br />
		手机号:<input type="text"name = "phone" id="phone"/>
		<span id="phoneSpan" style="font-size: 16pt;"></span>
		<br />
		身份证号:<input type="text"name = "status" id="status"/>
		<span id="statusSpan" style="font-size: 16pt;"></span>
		<br />
		地址:<input type="text"name = "address" id="address"/>
		<span id="addressSpan" style="font-size: 16pt;"></span>
		<br />
		<input type="button" value="校验" onclick="verify()" />
		<script type="text/javascript">
			function verify() {
				
				//用户名验证
				var user = "";
				user = document.getElementById("user").value;
				var pattl = /^[A-Z][a-zA-Z0-9_]{6,20}$/;
				var result = pattl.test(user.trim());
				if (result) {
					document.getElementById("userSpan").innerHTML = "√"
					document.getElementById("userSpan").style.fontSize = "20pt"
				} else {
					document.getElementById("userSpan").innerHTML = "×"
				}
				//密码验证
				var pwd = "";
				pwd = document.getElementById("pwd").value;
				var pattl = /^[A-Z][a-zA-Z0-9_]{8,15}$/;
				var result = pattl.test(pwd.trim());
				if (result) {
					document.getElementById("pwdSpan").innerHTML = "√"
					document.getElementById("pwdSpan").style.fontSize = "20pt"
				} else {
					document.getElementById("pwdSpan").innerHTML = "×"
				}
				
				//确认密码验证
				var pwds = "";
				pwds = document.getElementById("pwd2").value;
				var pattl = /^[A-Z][a-zA-Z0-9_]{8,15}$/;
				var result = pattl.test(pwds.trim());
				if (result) {
					document.getElementById("pwd2Span").innerHTML = "√"
					document.getElementById("pwd2Span").style.fontSize = "20pt"
				} else {
					document.getElementById("pwd2Span").innerHTML = "×"
				}
					
				
				//邮箱验证
				var emails = "";
				emails = document.getElementById("email").value;
				var pattl = /^[A-z0-9]+@[a-z0-9]+.com$/;
				var result = pattl.test(emails.trim());
				if (result) {
					document.getElementById("emailSpan").innerHTML = "√"
					document.getElementById("emailSpan").style.fontSize = "20pt"
				} else {
					document.getElementById("emailSpan").innerHTML = "×"
				}
 
				//手机号验证
				var phones = "";
				phones = document.getElementById("phone").value;
				var pattl = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
				var result = pattl.test(phones.trim());
				if (result) {
					document.getElementById("phoneSpan").innerHTML = "√"
					document.getElementById("phoneSpan").style.fontSize = "20pt"
				} else {
					document.getElementById("phoneSpan").innerHTML = "×"
				}
				
				//身份证号验证
				var status1 = "";
				status1 = document.getElementById("status").value;
				var pattl = /^([1-9]){1}[0-9]{17}|[1-9]{1}[0-9]{16}(x|X)"statusSpan").innerHTML = "√"
					document.getElementById("statusSpan").style.fontSize = "20pt"
				} else {
					document.getElementById("statusSpan").innerHTML = "×"
				}
				//地址验证
				var addres = "";
				addres = document.getElementById("address").value;
				var pattl = /^[\u4e00-\u9fa5]+[\u4E00-\u9FA5A-Za-z0-9_]+$/;
				var result = pattl.test(addres.trim());
				if (result) {
					document.getElementById("addressSpan").innerHTML = "√"
					document.getElementById("addressSpan").style.fontSize = "20pt"
				} else {
					document.getElementById("addressSpan").innerHTML = "×"
				}
				
			}
 
 
		</script>
	</body>
</html>

效果图如下:

js 输入框 正则表达式(菜鸟必看教程)

以上这篇js输入框使用正则表达式校验输入内容的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希

望大家多多支持。

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。