<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>联系方式正则表达式</title>
<script type="text/javascript" src="js/jquery1.8.min.js"></script>
<script type="text/javascript">
$(function (){
$("#txtPhone").focus(function () {
$(this).next().show().removeClass("onError").removeClass("onright").addClass("ontan").html("请输入你的联系电话");
}).blur(function () {
var patrn = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$)/;
if ($(this).val() != ""){
if (!patrn.exec($(this).val()))
$(this).next().removeClass("ontan").addClass("onError").html("联系电话格式不正确");
else
$(this).next().removeClass("ontan").removeClass("onError").addClass("onright").html(" ");
}
else
$(this).next().removeClass("ontan").addClass("onError").html("联系电话不能为空");
});
}); </script>
</head>
<body>
<div align="center">
联系方式<input type="text" id="txtPhone"/><label style="color: red;" class="onError"></label>
</div>
</body>
</html>