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

How to implement regular verification input of mobile phone number using jQuery

亚连
Release: 2018-06-14 11:32:27
Original
2048 people have browsed it

This article mainly introduces the jQuery implementation of mobile phone number regular verification input and automatic space filling functions, involving jQuery event response, string traversal and regular judgment and other related operating skills. Friends in need can refer to it

This article describes the example of jQuery's implementation of regular verification input and automatic filling of spaces for mobile phone numbers. Share it with everyone for your reference, the details are as follows:

Let’s take a look at the running effect first (you can delete it continuously when deleting):

Specific code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <input type="text" id="inp">
  <script src="jquery-1.12.3.min.js"></script>
  <script>
    $(function(){
      $("#inp").keyup(function(){
      /*
      手机号验证时:
       var pattern = /^1[3|4|5|7|8]\d{1}\s\d{4}\s\d{4}$/;
      pattern.test(str);
      */
        _self = $(this);
        if(_self.val().length == 3 || _self.val().length == 8){
          var str = _self.val()+" ";
          _self.val(str);
        }
      });
    });
  </script>
</body>
</html>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Use the http module to send requests through nodejs (detailed tutorial)

How to implement a table using jQuery CSS

How to use Vue to implement the comment framework

The above is the detailed content of How to implement regular verification input of mobile phone number using jQuery. 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