layui输入框验证
第一种:
1、验证必填项:lay-verify=”required” 2、数字验证:lay-verify=”int” 3、验证用户名:lay-verify=”username” 4、验证手机号:lay-verify=”phone” 5、验证邮箱:lay-verify=”email” 6、验证身份证:lay-verify=”identity” 7、验证日期:lay-verify=”date” 8、验证链接:lay-verify=”url” 9、自定义密码验证:lay-verify=”pass”
第二种:
<form id=‘formDemo‘ action="" method=‘POST‘ class="layui-form"> <input type="text" class="cell-input"name="type" lay-verify="type|required" placeholder="类型" autocomplete="off" /> <input type="text" class="cell-input"name="address" lay-verify="address|required" placeholder="请选择钱包地址" autocomplete="off" />
<input type="submit" class="btn-block btn-primary address_save" value="保存" lay-filter="formDemo" lay-submit/>
</form>
layui.use(‘form‘, function(){ var form = layui.form; //自定义验证规则 form.verify({type: function(value){ if(value == 0){ return ‘请选择正确种类‘; } } ,address: function(value){ if(value.length == 0){ return ‘地址不能为空‘; } } }); //监听提交 form.on(‘submit(formDemo)‘, function(data){ $.post("{:U(‘UserCenter/addAddressBook‘)}",data.field,function(res){ layer.msg(‘操作成功‘,{time:2000},function(){ window.location.href = "{:U(‘UserCenter/AddressBook‘)}"; }) }).error(function(xhr, status, info){layer.msg(‘操作失败‘)}); return false; }); });
原文:https://www.cnblogs.com/binweb/p/14537450.html