From b9afbcee51a1bcd50561d232c15949f49ee8920f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:11:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20form=20=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/form.html | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/form.html b/examples/form.html index 814dbf7d..0bed4744 100644 --- a/examples/form.html +++ b/examples/form.html @@ -170,7 +170,7 @@
- +
@@ -200,7 +200,7 @@
- @@ -380,19 +380,23 @@ var util = layui.util; var laydate = layui.laydate; - //自定义验证规则 + // 自定义验证规则 form.verify({ title: function(value){ - if(value.length < 5){ + if(value && value.length < 5){ // 值若填写时才校验 return '标题也太短了吧'; } + }, + pass: function(value) { + if (!/(.+){6,12}$/.test(value)) { + return '密码必须 6 到 12 位'; + } + }, + amount: function(value) { + if (value && !/^\d+\.\b\d{2}\b$/.test(value)) { // 值若填写时才校验 + return '金额必须为小数保留两位'; + } } - ,pass: [/(.+){6,12}$/, '密码必须6到12位'] - ,money: [ - /^\d+\.\b\d{2}\b$/ - ,'金额必须为小数保留两位' - ] - //,n: [/^(\d)+$/, '数字校验'] }); /*