效果图GIF
git地址:WxValidate
使用
import WxValidate from '../../utils/WxValidate'; Page({ data: { basicInfo: { tel: '', post: '', weChat: '', specialPlane: '', email: '', intro: '' } }, onLoad() { this.initValidate(); }, initValidate() { const rules = { tel: { required: true, tel: true, }, post: { required: true, }, weChat: { required: true, }, specialPlane: { required: true, }, email: { required: true, email: true } }; const messages = { tel: { required: '请输入手机号', tel: '请输入正确格式手机号', }, post: { required: '请输入职位', }, weChat: { required: '请输入微信号', }, specialPlane: { required: '请输入座机号', }, email: { required: '请输入电子邮箱', email: '请输入正确格式电子邮箱', } }; this.WxValidate = new WxValidate(rules, messages) }, formChange(val) { let obj = {} obj[`basicInfo.${val.currentTarget.dataset.val}`]= val.detail.value this.setData(obj) }, submitForm(e) { const params = e.detail.value if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0] this.showModal(error) return false } }, showModal(error) { wx.showToast({ title: error.msg, icon: 'none', duration: 2000 }) }, })
文章标题:微信小程序表单验证WxValidate的使用-创新互联
网页链接:https://www.cdcxhl.com/article2/ceicic.html
成都网站建设公司_创新互联,为您提供面包屑导航、自适应网站、动态网站、网站策划、建站公司、ChatGPT
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联