基础使用
<form bindsubmit="save">
<input name="informant" bindinput='informantInput' />
<button formType="submit" class="bottom">确认</button>
<form>
//引入
import { wxValidate } from '../../utils/wxValidate.js'
onLoad() {
this.WxValidate = new wxValidate(
{
//input的name对应informant
//informant属性对应的规则
informant: {
required: true,
minlength: 2,
maxlength: 10,
}
//....
},
//informant规则对应的提示语
{
informant: {
required: '请输入您的姓名',
minlength: '请输入您的姓名',
maxlength: '请输入您的姓名'
}
//....
}
)
}
//对应处理函数
handler(e) {
if (!this.WxValidate.checkForm(e)) {
const error = this.WxValidate.errorList[0]
console.log(error);
wx.showToast({
title: `${error.msg} `,
icon: 'none',
duration: 2000
})
return false
}
}
demo
zhangwh754/wx_validate_demo: wxValidate库的使用demo (github.com)
https://github.com/zhangwh754/wx_validate_demo
github文档:
wx-extend/validate.md at master · wux-weapp/wx-extend · GitHub:dog: 微信小程序 - 扩展插件(发送请求、Promise API、表单验证、Restful API) - wx-extend/validate.md at master · wux-weapp/wx-extend
https://github.com/wux-weapp/wx-extend/blob/master/docs/components/validate.md