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
This article introduces a detailed explanation of...
Problem: The null type data returned by mybatis d...
Table of contents redo log Why do we need to upda...
Table of contents 1. New usage of watch 1.1. Watc...
Recently, there is a need to automatically search...
Table of contents Scenario Try to solve solve Sce...
Record some of the processes of using node-media-...
In general applications, we use timestamp, dateti...
1. Use CSS Copy code The code is as follows: style...
The plugin is installed in the Firefox browser. T...
View the engines supported by the current databas...
1. Embedded Software Level 1) Bootloader->Boot...
First query table structure (sys_users): SELECT *...
This article example shares the specific code of ...
Install ZLMediaKit on centos6 The author of ZLMed...