HTML部分
<form class="layui-form" action="insertEnterprise-jump.php" method="post">
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-inline">
<input type="password" name="Epassword" lay-verify="required|pwd" class="layui-input"
placeholder="6到12位,且不能出现空格">
</div>
<label class="layui-form-label">确认密码</label>
<div class="layui-input-inline">
<input type="password" lay-verify="required|confirmPass" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
JS部分
注意需要调用jQuery。
layui.use('form', function () {
var form = layui.form;
var $ = layui.$ //由于layer弹层依赖jQuery,所以可以直接得到
, layer = layui.layer;
form.verify({
Eid: [
/^[S]{5,5}$/
, '号码必须5位数字!'
],
pwd: [
/^[S]{6,12}$/
, '密码必须6到12位,且不能出现空格'
],
confirmPass: function (value) {
if ($('input[name=Epassword]').val() !== value)
return '两次密码输入不一致!';
}
});
//监听提交
form.on('submit(formDemo)', function (data) {
// layer.msg(JSON.stringify(data.field));
return true;
});
});