WeChat applet form validation, for your reference, the specific content is as follows You need to use a plug-in WxValidat.js Portal Import it under the page js file you need to use import WxValidate from '../../utils/WxValidate.js' Main contentWXML Content <form bindsubmit="formSubmit"> <view class="weui-cells__title">Username</view> <view class="weui-cells weui-cells_after-title"> <view class="weui-cell weui-cell_input"> <input class="weui-input" type="text" name="userName" placeholder="Please enter your user name"/> </view> </view> <view class="weui-cells__title">Password</view> <view class="weui-cells weui-cells_after-title"> <view class="weui-cell weui-cell_input"> <input class="weui-input" type="text" name="password" placeholder="Please enter your password"/> </view> </view> <view class="weui-cells__title">Mobile phone number</view> <view class="weui-cells weui-cells_after-title"> <view class="weui-cell weui-cell_input"> <input class="weui-input" type="text" name="phone" placeholder="Please enter your phone number"/> </view> </view> <view class="btn-area"> <button formType="submit">Submit</button> <button formType="reset">Reset</button> </view> </form> js content /** * Life cycle function--listen for page loading*/ onLoad: function (options) { this.initValidate()//Validation rule function, initialize field rules and field prompt information}, initValidate() { const rules = { userName: { //Username required: true, minlength:2 }, password: { //password required: true }, phone:{ //Mobile numberrequired:true, tel:true } } const messages = { //prompt information userName: { required: 'Please fill in your name', minlength:'Please enter a correct name' }, password: { required: 'Please fill in your password' }, phone:{ required:'Please fill in your mobile number', Tel:'Please fill in the correct mobile phone number' } } this.WxValidate = new WxValidate(rules, messages) }, //Call verification function formSubmit: function (e) { console.log('Submit event occurred in the form, the data carried is:', e.detail.value) const params = e.detail.value //Check form if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0] console.log(error); return false } console.log("yes"); return true; }, It is worth noting that the errorList list of WxValidate returns an object. And the name of the field to be verified should correspond one to one with the name of the form component. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of the meaning of N and M in the MySQL data type DECIMAL(N,M)
>>: VMware Workstation 12 Pro Linux installation tutorial
Result:Implementation Code html <link href=...
Preface: Docker port mapping is often done by map...
How to refresh iframe 1. To refresh, you can use j...
Related articles: Beginners learn some HTML tags ...
Special statement: This article is translated bas...
student.xml <?xml version="1.0" enco...
1.ssh command In Linux, you can log in to another...
Source code preview: https://github.com/jdf2e/nut...
This article shares the specific code of the WeCh...
The select element creates a single-select or mult...
This article example shares the specific code of ...
When MySQL queries tens of millions of data, most...
Preface Creating shortcuts in Linux can open appl...
Table of contents 1. Basics 2. Nodes, trees, and ...
Preface: Basically, whether it is for our own use...