layui 表单自定义验证不生效的问题

推荐必看:https://blog.csdn.net/persistencegoing/article/details/84376427  

All rights reserved.No part of this article may be reproduced or distributed by any means,or stored in a database or retrieval system,without the prior written permission of persistenceGoing author

1.form 需在div 内部

layui 表单自定义验证不生效的问题_第1张图片

 

2.导入相应js和css

3.标签

layui 表单自定义验证不生效的问题_第2张图片

 

4.自定义验证使用

layui.use(['form'], function () {
        var form = layui.form;
        //要放在form.on上面,千万不能放在提交步骤中,否则会不触发
        form.verify({

           realName: function(value) {

                   //判断这个值,逻辑代码

            },

            digital: [
                /^[0-4]*$/
                ,'请填入0-4的分数'
            ]
        });

       //提交按钮触发
        form.on("submit(submit_button)", function (data) {
            return false;
        });
    });

 

5.自带的验证标签


phone:[/(^$)|^1\d{10}$/,'请输入正确的手机号'],
email:[/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,'邮箱格式不正确'],
url:[/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/,'链接格式不正确'],
number:[/(^$)|^\d+$/,'只能填写数字'],
date:[/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/,'日期格式不正确'],
identity:[/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/,'请输入正确的身份证号']

 

 

博主强烈推荐:https://blog.csdn.net/persistencegoing/article/details/84376427

希望大家关注我一波,防止以后迷路,有需要的可以加群讨论互相学习java ,学习路线探讨,经验分享与java求职  

群号:721 515 304

你可能感兴趣的:(前端)