一、实现的效果图:

二、CSS样式

/*验证样式*/
.onError{ vertical-align: middle;
color: #ff0000;
line-height: 22px;
padding: 2px 10px 2px 23px;
margin-left: 10px;
_margin-left: 5px;
background-image: url(../images/cuo.png);
background-repeat: no-repeat;
background-position: 0px 2px;
}
.onTan{ vertical-align: middle;
color: #343434;
line-height: 22px;
padding: 2px 10px 2px 23px;
margin-left: 10px;
_margin-left: 5px;
background-image: url(../images/tan.png);
background-repeat: no-repeat;
background-position: 0px 2px;
}
.onRight{
vertical-align: middle;
line-height: 22px;
padding: 2px 10px 2px 23px;
margin-left: 10px;
_margin-left: 5px;
background-image: url(../images/dui.png);
background-repeat: no-repeat;
background-position: 0px 2px;
}

二、JS

//发布快递专线(会员管理)
$(function () {
//鼠标指针触发是验证出发地网点联系电话是否合法
$("#txtStartLinkPhone").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").removeClass("onright").addClass("onError").html("出发地网点联系电话输入格式不正确");
else
$(this).next().removeClass("ontan").removeClass("onError").addClass("onright").html(" ");
}
else
$(this).next().removeClass("ontan").removeClass("onright").addClass("onError").html("出发地网点联系电话不能为空");
});
});

//button按钮提交时验证输入的电话是否合法
function StartLinkPhone() {
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 ($("#txtStartLinkPhone").val() != "") {
if (!patrn.exec($.trim($("#txtStartLinkPhone").val()))) {
$(this).next().removeClass("ontan").removeClass("onright").addClass("onError").html("出发地网点联系电话输入格式不正确");
return false;
}
else {
$(this).next().removeClass("ontan").removeClass("onError").addClass("onright").html(" ");
return true;
}
}
else {
$(this).next().removeClass("ontan").removeClass("onright").addClass("onError").html("出发地网点联系电话不能为空");
return false;
}
}

三、页面

<form id=form1>
<table cellspacing="10" cellpadding="10">
<tr>
<td class="td1">联系电话:<em class="red">*</em></td>
<td class="td2"><input type="text" id="txtStartLinkPhone" name="txtStartLinkPhone" value="@expressline.StartLinkPhone"></td>
</tr>
<tr>
    <td class="td1"></td>
    <td class="td2"><input name="add" type="submit" value="添加" class="left btn3"></td>
  </tr>
</table>
</form>
@section Js{
<script src="/js/expressline.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#txtStartLinkPhone").after("<span></span>");
$("#form1").submit(function () {
if(!StartLinkPhone()) {
$("#txtStartLinkPhone").focus().blur();
}
else {
$.post("/member/publishexpressline?action=get", $("this").serializeArray(), function (json) {
if (json.code == 1) {
//成功
alert(json.msg);
window.location = "/Member/ExpressLineManage";
}
else {
//失败
alert(json.msg);
}
});
}
return false;
}
})
</script>
}

联系电话正则表达式(jquery表单验证)的更多相关文章

  1. python_way day17 jQuery表单验证,事件绑定,插件,文本框架,正则表达式

    python_way day17 1.jQuery表单验证 dom事件绑定 jquery事件绑定 $.each return值的判断 jquery扩展方法 2.前段插件 3.jDango文本框架 4. ...

  2. jquery表单验证使用插件formValidator

    JQuery表单验证使用插件formValidator 作者: 字体:[增加 减小] 类型:转载 时间:2012-11-10我要评论 jquery表单验证使用插件formValidator,可供有需求 ...

  3. jQuery表单验证以及将表单序列化为json对象小练习

    jquery表单验证(非实时验证),同时,将表单序列化为json对象提交表单. <!DOCTYPE html> <html lang="en"> <h ...

  4. 【jquery】Validform,一款不错的 jquery 表单验证插件

    关于 Validform 这是一款很不错的 jquery 表单验证插件,它几乎能够满足任何验证需求,仅仅一行代码就能搞定整站的表单验证. $('form').Validform(); 为什么能如此方便 ...

  5. 【jQuery基础学习】06 jQuery表单验证插件-Validation

    jQuery的基础部分前面都讲完了,那么就看插件了. 关于jQuery表单验证插件-Validation validation特点: 内置验证规则:拥有必填.数字.E-Mail.URL和信用卡号码等1 ...

  6. jQuery 表单验证插件 jQuery Validation Engine 使用

    jQuery 表单验证插件 jQuery Validation Engine 使用方式如下: 1.引入头文件(注意一定要把jQuery放在前面),指定使用 jQuery Validation Engi ...

  7. JQuery 表单验证--jquery validation

    jquery validation,表单验证控件 官方地址 :http://jqueryvalidation.org/ jquery表单验证 默认值校验规则 jquery表单验证 默认的提示 < ...

  8. jquery validate强大的jquery表单验证插件

    jquery validate的官方演示和文档地址: 官方网站:http://jqueryvalidation.org/ 官方演示:http://jqueryvalidation.org/files/ ...

  9. jQuery框架学习第十一天:实战jQuery表单验证及jQuery自动完成提示插件

    jQuery框架学习第一天:开始认识jQueryjQuery框架学习第二天:jQuery中万能的选择器jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQuer ...

  10. jquery 表单验证插件

    其他: <form action=""> First name: <input type="text" name="FirstNam ...

随机推荐

  1. 编写你自己的单点登录(SSO)服务

    王昱 yuwang881@gmail.com   博客地址http://yuwang881.blog.sohu.com 摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软件系统其中.本文从 ...

  2. EntityFramework Code First 优化-IIS 8的第一次优化请求配置

    首先需要在Window中添加Application Initialization Application Initialization 在IIS中配置Application Pool 编辑Applic ...

  3. Codeforces Round #311 (Div. 2) C. Arthur and Table Multiset

    C. Arthur and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/p ...

  4. Codeforces Round #308 (Div. 2)B. Vanya and Books 数学

    B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

  5. workflow 工作流

    https://documentation.devexpress.com/#Xaf/CustomDocument3356

  6. AJAX responseText vs responseXML

    AJAX------>本质 Request/Response(Server)模式 response的形式 responseText--------->获得字符串形式的响应数据. ----- ...

  7. stm32 IAP + APP ==>双剑合一

    (扩展-IAP主要用于产品出厂后应用程序的更新作用,上一篇博文详细的对IAP 升级程序做了详细的分析http://blog.csdn.net/yx_l128125/article/details/12 ...

  8. .net 调用C++类库

    事实上这一直是个非常无解的问题.最好的办法是将C++类库写成COM. 可是有时候往往不能这个做.那就仅仅有两种办法:转成C函数形式或者Manage C++封装. 下文就介绍了这两种方法. 原帖:htt ...

  9. centos 7 没有ifconfig 命令

    centos 7 没有ifconfig 命令: 安装命令: yum install net-tools

  10. oc-17-description

    Book.h #import <Foundation/Foundation.h> @interface Book : NSObject { NSString *_bookName; // ...