<script src="${pageContext.request.contextPath}/resources/js/jquery-1.12.0.min.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/resources/js/jquery.validate.min.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/resources/js/messages_zh.js" type="text/javascript"></script>

<form class="am-form" id="mechantForm" class="doc-vld-msg">
                            <div class="am-form-group">
                                <label for="doc-ipt-name-1" class="labelname">厂商名称:</label>
                                <input type="text" id="merchantName" name="merchantName" minlength="3" placeholder="输入厂商名称" required/>
                            </div>
                            <div class="am-form-group">
                                <label for="doc-ipt-name-1" class="labelname">姓名:</label>
                                <input type="text" name="name" id="name" placeholder="请输入姓名">
                            </div>
                            <div class="am-form-group">
                                <label for="doc-ipt-phone-1" class="labelname">电话:</label>
                                <input type="text" name="telphone" id="telphone" placeholder="请输入电话">
                            </div>
                            <div class="am-form-group">
                                <label for="doc-ipt-phone-1" class="labelname">公司地址:</label>
                                <input type="text" name="address" id="address" placeholder="请输入公司地址">
                            </div>
                            <div style="margin-left:15%;margin-top:27px;">
                                <button style="margin-right:20px;" type="button" data-am-modal-close  class="mybtn">关闭</button>
                                <button type="submit"  class="mybtn"  id='saveBtn'>确定</button>
                            </div>
</form>

js部分:

jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile = /^1[34578]\d{9}$/;/*/^1(3|4|5|7|8)\d{9}$/*/
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "请正确填写您的手机号码");

$("#saveBtn").click(function() {
        
              $("#mechantForm").validate({
                  submitHandler: function(form){  
                      $.ajax({
                            cache : true,
                            type : "POST",
                            url : "merchant",
                            data : $('#mechantForm').serialize(),
                            async : false,
                            error : function(data) {
                                layer.alert('系统错误', {icon: 0});
                            },
                            success : function(data) {
                                layer.alert('保存成功', {icon: 1});
                                $('#mechantForm')[0].reset();
                            }
                        });
                         },
                    rules: {
                        merchantName: {
                            required: true,
                             minlength: 3
                        },
                        name:{
                            required: true,
                             minlength: 2
                        },
                        telphone:{
                            required: true,
                            minlength: 11,
                            maxlength:11,
                            digits:true,
                            number:true,
                            isMobile : true
                        },
                        address:{
                            required: true,
                            maxlength:50
                        }
                    },
                    messages: {
                        merchantName: {
                            required: "不能为空",
                             minlength: "不能少于3个字符"
                        },
                        name:{
                            required: "不能为空",
                             minlength: "不能少于2个字符"
                        },
                        telphone:{
                            required: "不能为空",
                            minlength: "必须11位数字",
                            maxlength:"必须11位数字",
                            digits:"必须是数字"    ,
                            number:"请输入有效数字",
                            isMobile : "手机号格式错误"
                        },
                        address:{
                            required:'不能为空',
                            maxlength:"不能多于50个字符"
                        }
                    }
                });
    });

jquery验证插件validate自定义扩展的更多相关文章

  1. jQuery验证插件 Validate详解

    1.引入必要的文件,以及语言中文提示包 2.使用规则如下: 序号 规则 描述 1 required:true 必须输入的字段. 2 remote:"check.php" 使用 aj ...

  2. jquery 验证插件 validate

    1)required:true 必输字段(2)remote:"check.php" 使用ajax方法调用check.php验证输入值(3)email:true 必须输入正确格式的电 ...

  3. 表单验证插件——validate

    表单验证插件——validate 该插件自带包含必填.数字.URL在内容的验证规则,即时显示异常信息,此外,还允许自定义验证规则,插件调用方法如下: $(form).validate({options ...

  4. jQuery验证插件

    原文:jQuery验证插件 学习要点: 1.使用 validate.js 插件 2.默认验证规则 3.validate()方法和选项 4.validate.js 其他功能 验证插件(validate. ...

  5. jQuery Validate 表单验证插件----Validate简介,官方文档,官方下载地址

     一. jQuery Validate 插件的介绍 jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆 ...

  6. jQuery应用一之验证插件validate的使用

    综述 validate是一个用来验证表单提交的插件,应用十分广泛,具有如下的几个功能 自带了基本的验证规则 提供了丰富的验证信息提示功能 多种事件触发验证 自定义验证规则 下面我们就来感受一下这个插件 ...

  7. Jquery表单验证插件validate

    写在前面: 在做一些添加功能的时候,表单的提交前的验证是必不可少的,jquery的validate插件就还可以,对于基本的需求已经够了.这里记录下基本的用法. 还是写个简单的demo吧 <htm ...

  8. 第九章 jQuery验证插件简介

    1. 表单验证插件-----Validation <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  9. jQuery验证插件使用初步

    validate是一款优秀的表单验证插件,其初步使用方法如下: (1)前台页面代码: <form id="form1" runat="server"> ...

随机推荐

  1. createuser - 定义一个新的 PostgreSQL 用户帐户

    SYNOPSIS createuser [ option...] [ username] DESCRIPTION 描述 createuser 创建一个新的 PostgreSQL 用户.只有超级用户(在 ...

  2. CREATE LANGUAGE - 定义一种新的过程语言

    SYNOPSIS CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name HANDLER call_handler [ VALIDATOR valfunctio ...

  3. Stack in c#

    public static void SaveStack() { string result = "Hello World"; Stack st = new Stack(); fo ...

  4. pytorch笔记:09)Attention机制

    刚从图像处理的hole中攀爬出来,刚走一步竟掉到了另一个hole(fire in the hole*▽*) 1.RNN中的attentionpytorch官方教程:https://pytorch.or ...

  5. sqlite3接口简要说明

    本文介绍一下SQLite C/C++接口. 早期的SQLite C/C++接口只有5个接口函数, 很容易学习. 新版本的SQLite新增了很多功能, 目前大概有185个API接口.本文介绍一些核心的A ...

  6. Bootstrap table的基础用法

    一.官方文档 Bootstrap 中文网:http://www.bootcss.com/ Bootstrap Table 中文网 : http://bootstrap-table.wenzhixin. ...

  7. loader.js

    /** * @preserve Tiny-Loader: A small loader that load CSS/JS in best way for page performanceIs. * * ...

  8. react-native IOS Build input file cannot be found: '~~~~~/node_modules/react-native/Libraries/WebSocket/libfishhook.a'

    尝试添加或者删除libfishhook.a 如果解决了你的问题请点个赞!

  9. python爬取网页图片

    # html:网页地址 def getImg2(html): soup = BeautifulSoup(html, 'html.parser') href_regex = re.compile(r'^ ...

  10. Format 格式化函数

    转自:老百姓 Format是一个很常用,却又似乎很烦的方法,本人试图对这个方法的帮助进行一些翻译,让它有一个完整的概貌,以供大家查询之用: 首先看它的声明:function Format(const ...