<!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>
<title>正则表达式验证</title>
<script type="text/javascript" src="https://www.jb51.net/Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
var Validate = {
isTel: function (s) {
var patrn = /^((\+?86)|(\(\+86\)))?\d{3,4}-\d{7,8}(-\d{3,4})?$/
if (!patrn.exec(s)) return false
return true
},
isMobile: function (value) {
var validateReg = /^((\+?86)|(\(\+86\)))?1\d{10}$/;
return validateReg.test(value);
},
cellPhone: function () {
var cellPhoneNumber = $("#txtCellPhone").val();
if (!Validate.isMobile(cellPhoneNumber)) {
alert("手机号码格式不正确");
return false;
} else {
alert("您的手机号码格式是正确的");
}
},
telePhone: function () {
var telePhoneNumber = $("#txttelePhone").val();
if (!Validate.isTel(telePhoneNumber)) {
alert("电话号码格式不正确");
return false;
} else {
alert("您的电话号码格式是正确的");
}
}
}
</script>
</head>
<body>
<div>
<label>请输入手机号码(支持+86):</label><input type="text" /><input type="button" value="验证"/><br />
<label>请输入电话号码(支持+86):</label><input type="text" /><input type="button" value="验证"/><br />
</div>
</body>
</html>