All rights reserved.No part of this article may be reproduced or distributed by any means,or stored in a database or retrieval system,without the prior written permission of persistenceGoing author
1.form 需在div 内部
2.导入相应js和css
3.标签
4.自定义验证使用
layui.use(['form'], function () {
var form = layui.form;
//要放在form.on上面,千万不能放在提交步骤中,否则会不触发
form.verify({
realName: function(value) {
//判断这个值,逻辑代码
},
digital: [
/^[0-4]*$/
,'请填入0-4的分数'
]
});
//提交按钮触发
form.on("submit(submit_button)", function (data) {
return false;
});
});
5.自带的验证标签
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:[/(^$)|^\d+$/,'只能填写数字'],
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)$)/,'请输入正确的身份证号']