JQ的表单验证
(function () { $("#but").click(function () { if ($("#name").val() == "" || $("#name").val() == "请输入您的真实姓名") { alert("请输入患者姓名"); return false; } if ($("#tel").val() == "" || $("#tel").val() == "输入您的常用电话号码") { alert("请输入电话号码"); return false; } if ($("#date").val() == "" || $("#date").val() == "点击选择就诊日期") { alert("请输入就诊日期"); return false; } var tels = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/; var pattern = /^[\u4E00-\u9FA5]{1,6}$/; if (!pattern.test($('#name').val())) { alert("正确的姓名!"); return false; } if (!tels.test($('#tel').val())) { alert("请正确填写电话号码!"); return false; } }) })();
-----------------------------------------------------------------------小二给我来二两轮子!