<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. codeforces_1075_C. The Tower is Going Home

    http://codeforces.com/contest/1075/problem/C 题意:一个长宽均为1e9的棋盘,n个垂直障碍在x列无限长,m个水平障碍在第y行从第x1列到x2列.可以水平和垂 ...

  2. swift 使用计算属性+结构管理内存

    class GooClass { deinit { print("aaaaaaaa") } var str = "gooClass" } struct GooS ...

  3. 数据结构算法 - ConcurrentHashMap 源码解析

    五个线程同时往 HashMap 中 put 数据会发生什么? ConcurrentHashMap 是怎么保证线程安全的? 在分析 HashMap 源码时还遗留这两个问题,这次我们站在 Java 多线程 ...

  4. 自动化测试selenium + request + 动态加载页面

    # demo01from selenium import webdriver from time import sleep bro = webdriver.Chrome(executable_path ...

  5. windows SDK创建一个窗体

    #include <windows.h> /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, U ...

  6. incremental linking(增量链接)的作用

    转:incremental linking(增量链接)的作用 今天编译一个C++程序时,报了一个奇怪的错误(之前是好好的): 1>LINK : fatal error LNK1123: fail ...

  7. freenas 系统可能存在的bug

    1.portal 中ip端口显示有问题. 2.创建extend/target映射之后重启iscsi服务有的时候不能启动. 3.后台/usr /etc 重启系统会自动还原.

  8. CentOS中一些基本的操作记录

    1)切换到root su root 输入你的密码.我的是123

  9. CSS工具、CSS重置(CSS Reset)

    样式重置的目的是减少浏览器的不一致性,例如line-height,margin,标题的font-size大小等等.样式重置经常在CSS框架中出现. 这里的重置样式故意写的很一般,例如没有为body元素 ...

  10. HDOJ 1846 Brave Game - 博弈入门

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1846 经典基础博弈,首先面对(m+1)的人一定会输,依次往后推即可: #include<iost ...