惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - 大山008

若依导出excel时decimal数据千分位格式化 SpringBoot如何引入deepseek-多轮对话 EasyExcel实现百万级数据导入导出 SpringAMQP整合RabbitMQ使用 win11安装redis步骤详解 ftp与sftp工具类 stream流的一些常用用法 子类的toString方法如何打印父类的属性 MySQL常见的几种优化方案 关于若依AsyncFactory的一些思考,记录一下 Vue 路由跳转、路由传参、跳转区别、传值取值 MYSQL中substring_index()用法 mybatis sql 解决 in 参数过多的问题 MySQL之json数据操作 mybatis查询返回map键值对的问题 在vue中用multipart/form-data方式上传文件并同表单同步提交数据 Java微信转发及网络检测 生成带有二维码的海报 java将指定文件夹下面的所有图片压缩到指定大小以内并保存图片 Lock与ReentrantLock、Synchronized
validate校验,记录一种思路
大山008 · 2023-04-12 · via 博客园 - 大山008

场景:表单完全是动态循环出来的:

1、必填校验

//必填标志//requid动态必填
<div class="form-group" th:if="${t.fieldType==1}">
   <label class="" th:classappend="${t.isRequired}==1 ? 'col-sm-3 control-label is-required' : 'col-sm-3 control-label' " th:text="${t.fieldTitle}+':'"></label>
   <div class="col-sm-8">
       <input class="form-control" th:placeholder="${t.fieldDesc}" th:name="${t.fieldName}" th:id="${t.fieldName}" 
type
="text" th:required="${t.isRequired}==1?true:false"/> </div> </div>

2、手机号校验

  //因为整个表单时循环出来的,字段也是动态的,所以无法通过固定的name属性或者自定义使用validate校验,

    如:

$("#formId").validate({ //#formId form表单id
        rules:{
            //字段的name属性:"校验器"
            userName:"required",//required在此含义是必填
            //字段的name属性:{校验器:值,校验器:值}
            passWord:{
                required:true,
                digits:true //digits是整数校验器,后面写true表示启动此校验器
            }
        }
  });

考虑在循环中:

 let rulesObj={};
  for(let item of phoneList){
    rulesObj[item]={
      isPhone:true
    }
  }
  console.log(rulesObj);
  $("#form-task").validate({
    onkeyup: false,
    rules:rulesObj,
    focusCleanup: true
  });