Home Web Front-end JS Tutorial How to achieve password consistency in validation forms in jQuery

How to achieve password consistency in validation forms in jQuery

Jun 22, 2018 pm 04:41 PM
jquery Phone number regular expression Mail verify

This article mainly introduces jQuery's method of verifying form password consistency and regular expression verification of email and mobile phone number. It involves jQuery form element acquisition and regular verification related operation skills. Friends in need can refer to the following

The example in this article describes how jQuery implements the method of verifying the consistency of form passwords and verifying email and mobile phone numbers with regular expressions.

jQuery script

<script type="text/javascript">
function check_password() {
  if ($("#password").val() != $("#checkPWD").val()){
    alert("请保证两次输入密码的一致性!");
    $("#checkPWD").focus();
  }
}
function check_email() {
  var reg = /\w+[@]{1}\w+[.]\w+/;
  if (!reg.test($("#email").val())){
    alert("请输入正确的email!");
    $("#email").focus();
  }
}
function check_phone() {
  var reg = /^1[34578]\d{9}$/;
  if (!reg.test($("#phone").val())){
    alert("请输入正确的手机号!");
    $("#phone").focus();
  }
}
</script>
Copy after login

html file

<!DOCTYPE html>
<html>
<head>
  <script src="jquery1.3.2.js"></script>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>注册界面</title>
</head>
<body>
  <center>
    <h1>用户注册</h1>
    <form action="" method="post">
      <table width="400px" cellspacing="0px" cellpadding="0px" border="1px">
        <tr>
          <td>用户名</td>
          <td><input type="text" name="username" placeholder="用户名为3-12位字母数字或下划线组合" ></td>
        </tr>
        <tr>
          <td>密 码</td>
          <td><input type="password" name="password" placeholder="密码长度为6-12位的纯数字" id="password"></td>
        </tr>
        <tr>
          <td>确认密码</td>
          <td><input type="password" name="checkPWD" placeholder="密码长度为6-12位的纯数字" id="checkPWD" onchange="check_password()"></td>
        </tr>
        <tr>
          <td>手机号码</td>
          <td><input type="text" name="phone" placeholder="请输入正确的手机号码格式" id="phone" onchange="check_phone()"></td>
        </tr>
        <tr>
          <td>邮箱</td>
          <td><input type="email" name="email" placeholder="请输入正确邮箱格式" id="email" onchange="check_email()" required="required"></td>
        </tr>
        <tr>
          <td colspan="2" style="text-align:center">
            <input type="submit" value="注册">
            <input type="reset" value="重置">
          </td>
        </tr>
      </table>
    </form>
  </center>
</body>
</html>
Copy after login

Run result:

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

Related articles:

How to add a mobile phone verification code component in Vue

How to use state and setState in react (details Tutorial)

How to use the React Native screenshot component (detailed tutorial)

How to determine whether jQuery is loaded

How to use mui back to return to refresh the page

The above is the detailed content of How to achieve password consistency in validation forms in jQuery. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
Download the official website of Ouyi Exchange app for Apple mobile phone Download the official website of Ouyi Exchange app for Apple mobile phone Apr 28, 2025 pm 06:57 PM

The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Apr 28, 2025 pm 07:51 PM

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

How to log out of Binance How to log out of Binance How to log out of Binance How to log out of Binance Apr 28, 2025 pm 07:45 PM

To cancel a Binance account, you need to complete the following steps: 1) Ensure all asset transfers, 2) Cancel all pending orders, 3) Unlock API keys, 4) Close all open contracts; then log in to Binance official website, enter the "User Center", select "Account Logout", fill in the reason for the cancellation, confirm the asset transfer, submit an application and wait for review, confirm the cancellation after the review is passed, and the account cannot be restored after the cancellation.

Binance official website entrance Binance official latest entrance 2025 Binance official website entrance Binance official latest entrance 2025 Apr 28, 2025 pm 07:54 PM

Visit Binance official website and check HTTPS and green lock logos to avoid phishing websites, and official applications can also be accessed safely.

How to download, install and register the Hong Kong Digital Currency Exchange app 2025 How to download, install and register the Hong Kong Digital Currency Exchange app 2025 Apr 30, 2025 pm 07:18 PM

The download, installation and registration process of the Hong Kong Digital Currency Exchange app is very simple. Users can quickly obtain and use this app through the official app download link provided in this article. This article will introduce in detail how to download, install and register the Hong Kong Digital Currency Exchange app to ensure that every user can complete the operation smoothly.

Top 10 cryptocurrency apps recommended in 2025 Virtual currency trading platform app rankings Top 10 cryptocurrency apps recommended in 2025 Virtual currency trading platform app rankings Apr 30, 2025 am 10:33 AM

Recommended top ten cryptocurrency apps in 2025: 1. OKX, 2. Binance, 3. Coinbase. 1. OKX ranks first with its powerful features and user-friendly interface, supporting a variety of transactions and staking services. 2. Binance ranks second with its huge user base and rich trading pairs, providing a variety of trading and IEO services. 3. Coinbase ranks third with its user-friendly interface and powerful security measures, supporting a variety of mainstream virtual currency transactions.

Top 10 Virtual Digital Currency Exchanges Ranking List The latest list of Top 10 Virtual Currency Exchanges Top 10 Virtual Digital Currency Exchanges Ranking List The latest list of Top 10 Virtual Currency Exchanges Apr 30, 2025 am 10:21 AM

Top 10 virtual digital currency exchanges rankings: 1. OKX, 2. Binance, 3. Coinbase. 1. OKX ranks first with its powerful features and user-friendly interface, supporting a variety of transactions and staking services. 2. Binance ranks second with its huge user base and rich trading pairs, providing a variety of trading and IEO services. 3. Coinbase ranks third with its user-friendly interface and powerful security measures, supporting a variety of mainstream virtual currency transactions.

Ouyi Trading App Official Website Download Portal Ouyi Trading App Official Website Ouyi Trading App Official Website Download Portal Ouyi Trading App Official Website Apr 24, 2025 pm 02:15 PM

Through the following steps, you can safely access the Ouyi official platform and download the APP: 1. Use a trusted search engine to search for "Ouyi" or "OKX" to check the domain name; 2. Check the official social media account to obtain the URL; 3. Consult the official customer service to confirm the URL; 4. Use a trusted navigation website. When downloading the APP, visit the official website, find the download portal, choose how to scan the QR code, app store, or directly download the APK file, and pay attention to checking developer information, viewing user reviews, installing security software, beware of phishing websites and APPs from unknown sources, and protecting personal information.

See all articles