From 4738846f9301d754e78a68716b19e7f9b2a5c9c5 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 11:58:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20form=20=E6=96=87=E6=A1=A3?= =?UTF-8?q?=20`form.verify()`=20=E6=96=B9=E6=B3=95=E4=BB=8B=E7=BB=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/form/examples/form.verify.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/form/examples/form.verify.md b/docs/form/examples/form.verify.md index b85fb5a7..c0f68f56 100644 --- a/docs/form/examples/form.verify.md +++ b/docs/form/examples/form.verify.md @@ -13,8 +13,7 @@ layui.use(function(){ // 自定义验证规则,如下以验证用户名和密码为例 form.verify({ - // 函数写法 - // 参数 value 为表单的值;参数 item 为表单的 DOM 对象 + // 参数 value 为表单的值;参数 item 为表单元素 username: function(value, item){ if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){ return '用户名不能有特殊字符'; @@ -22,15 +21,17 @@ layui.use(function(){ if(/(^_)|(__)|(_+$)/.test(value)) return '用户名首尾不能出现 _ 下划线'; if(/^\d+$/.test(value)) return '用户名不能全为数字'; - // 若不想自动弹出默认提示框,可返回 true,这时你可以通过其他提示方式替代(v2.5.7 新增) + // 若不想自动弹出默认提示框,可返回 true,这时可通过其他提示方式替代(v2.5.7 新增) if(value === 'xxx'){ alert('用户名不能为敏感词'); return true; } }, - // 数组写法。 - // 数组中两个成员值分别代表:[正则表达式、正则匹配不符时的提示文字] - password: [/^[\S]{6,12}$/, '密码必须为6到12位的非空字符'] + password: function(value) { + if (!/^[\S]{6,12}$/.test(value)) { + return '密码必须为 6 到 12 位的非空字符'; + } + } }); // 提交事件 @@ -48,4 +49,4 @@ layui.use(function(){ return false; // 阻止默认 form 跳转 }); }) - \ No newline at end of file +