<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<input type="number" id="phone" name="phone" placeholder="请输入手机号" onblur="Isphone()"/>
<input type="text" id="email" name="email" placeholder="请输入邮箱" onblur="Isemail()"/>
<script>
function Isphone(){
var phone=document.getElementById(‘phone‘).value
var flag = false;
var message = "";
var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0-9]{1})|(15[0-3]{1})|(15[4-9]{1})|(18[0-9]{1})|(199)) d{8})$/;
if (!myreg.test(phone)) {
// console.log("手机号码不能为空");
message = "请输入有效的手机号码!";
} else if (phone.length != 11) {
//console.log("请输入11位手机号码!");
message = "请输入11位手机号码!";
} else if (phone==‘‘) {
//console.log("请输入有效的手机号码!");
message = "不能为空";
}
alert(message)
}
function Isemail(){
var em=document.getElementById(‘email‘).value
if (em == "")
{
alert("请输入电子信箱!");
}
else{
//对电子邮件的验证
var myreg = /^([a-zA-Z0-9] [_|_|.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9] [_|_|.]?)*[a-zA-Z0-9] .[a-zA-Z]{2,3}$/;
if(!myreg.test(em)){
alert(‘提示:请输入有效的E_mail!‘);
}
}
}
</script>
</body>
</html>
亲测,没啥大问题