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

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 大山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
  });