Home > Web Front-end > JS Tutorial > body text

WeChat applet implements simple input regular expression verification function sharing

小云云
Release: 2018-05-16 17:09:28
Original
3720 people have browsed it

This article mainly introduces the simple input regular expression verification function of the WeChat applet. It analyzes the input component event binding and regular expression verification related operation skills of the WeChat applet in the form of examples. Friends who need it can refer to it. I hope it can help. Everyone.

The example in this article describes the implementation of simple input regular expression verification function by WeChat applet. Share it with everyone for your reference, the details are as follows:

1. Effect display

2. Key code

index.wxml file

<input placeholder="输入内容" bindinput="check"></input>
<view>输入结果:{{result}}</view>
Copy after login

index.js file

Page({
  data:{
    result:&#39;&#39;
  },
  check:function(e){
    var regLowerCase=new RegExp(&#39;[a-z]&#39;,&#39;g&#39;);//判断用户输入的是否为小写字母
    var regCapitalLetter=new RegExp(&#39;[A-Z]&#39;,&#39;g&#39;);//判断用户输入的是否为大写字母
    var regNum=new RegExp(&#39;[0-9]&#39;,&#39;g&#39;);//判断用户输入的是否为数字
    var rsLowerCase=regLowerCase.exec(e.detail.value);
    var rsCapitalLetter=regCapitalLetter.exec(e.detail.value);
    var rsNum=regNum.exec(e.detail.value);
    if(rsLowerCase){
      this.setData({
        result:&#39;您输入的是小写字母&#39;
      })
    }else if(rsCapitalLetter){
      this.setData({
        result:&#39;您输入的是大写字母&#39;
      })
    }else if(rsNum){
      this.setData({
        result:&#39;您输入的是数字&#39;
      })
    }else{
      this.setData({
        result:&#39;&#39;
      })
    }
  }
})
Copy after login

3. Click here for the complete example codeDownload from this site.

Related recommendations:

input type=file Select pictures and achieve preview effects Detailed explanation

WeChat applet input input and Dynamically setting the button method

Using css to hide the input cursor method

The above is the detailed content of WeChat applet implements simple input regular expression verification function sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template