mvlidator
v1.0.1
Published
a form validator
Downloads
3
Readme
使用方法
<script src='mvalidator.js'></script>
结构要求
<form id="form">
<label data-name='user'>
<input type="text" />
</label>
<label data-name = "pass">
<input type="password" />
</label>
<label data-name='sex'>
男<input type="radio" name='sex' value="男"/>
</label>
<label data-name='sex'>
女<input type="radio" name="sex" value="女"/>
</label>
<button data-type='submit'>提交</button>
</form>
以form元素进行包裹,label元素传入data-name属性
提交按钮必须要data-type='submit'属性
使用方法
mvalidator({
target:'#form',//传入对应的form的id或者class
rules:{//传入对应的规则键名为表单元素的data-name属性
'user':{required:true,min:5,max:5,mseeage:'xxx'},//
'pass':{required:true,min:8,max:12,message:'xxx'},
},
trigger:'input',//触发验证的行为事件
submit:function(data){//点击提交的返回函数,验证通过则返回对应的数据
console.log(data)
}
})
验证规则说明
required:true|false 表示是否必填
min:number 表示最小的长度
max:number 表示最大的长度
regexp:string 表示正则匹配
email:true|false 表示邮箱验证
phone:true|false 表示电话验证