From 68a9ab79996c0b0406f54990833b204b24173aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 14 May 2023 11:47:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20form=20=E4=B8=AD=E5=86=85?= =?UTF-8?q?=E7=BD=AE=E9=AA=8C=E8=AF=81=E8=A7=84=E5=88=99=E7=9A=84=E9=80=97?= =?UTF-8?q?=E5=8F=B7=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/form.js | 53 +++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/modules/form.js b/src/modules/form.js index 1ce93847..08aa3a12 100644 --- a/src/modules/form.js +++ b/src/modules/form.js @@ -16,36 +16,37 @@ layui.define(['lay', 'layer', 'util'], function(exports){ var Form = function(){ this.config = { + // 内置的验证规则 verify: { required: [ - /[\S]+/ - ,'必填项不能为空' - ] - ,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: function(value){ + /[\S]+/, + '必填项不能为空' + ], + 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: function(value){ if(!value || isNaN(value)) return '只能填写数字' - } - ,date: [ - /^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/ - ,'日期格式不正确' + }, + 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)$)/, + '请输入正确的身份证号' ] - ,identity: [ - /(^\d{15}$)|(^\d{17}(x|X|\d)$)/ - ,'请输入正确的身份证号' - ] - } - ,autocomplete: null // 全局 autocomplete 状态。null 表示不干预 + }, + autocomplete: null // 全局 autocomplete 状态。 null 表示不干预 }; };