微信小程序表单验证WxValidate的使用
效果图GIF
git地址:WxValidate
使用
importWxValidatefrom'../../utils/WxValidate';
Page({
data:{
basicInfo:{
tel:'',
post:'',
weChat:'',
specialPlane:'',
email:'',
intro:''
}
},
onLoad(){
this.initValidate();
},
initValidate(){
construles={
tel:{
required:true,
tel:true,
},post:{
required:true,
},weChat:{
required:true,
},specialPlane:{
required:true,
},email:{
required:true,
email:true
}
};
constmessages={
tel:{
required:'请输入手机号',
tel:'请输入正确格式手机号',
},post:{
required:'请输入职位',
},weChat:{
required:'请输入微信号',
},specialPlane:{
required:'请输入座机号',
},email:{
required:'请输入电子邮箱',
email:'请输入正确格式电子邮箱',
}
};
this.WxValidate=newWxValidate(rules,messages)
},
formChange(val){
letobj={}
obj[`basicInfo.${val.currentTarget.dataset.val}`]=val.detail.value
this.setData(obj)
},
submitForm(e){
constparams=e.detail.value
if(!this.WxValidate.checkForm(params)){
consterror=this.WxValidate.errorList[0]
this.showModal(error)
returnfalse
}
},
showModal(error){
wx.showToast({
title:error.msg,
icon:'none',
duration:2000
})
},
})
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。