


jquery regular expression verification (mobile phone number, ID number, Chinese name)_jquery
The content that needs to be verified in the example of this article: Chinese name, mobile phone number, ID card and address. The verification method is shared with everyone for your reference. The specific content is as follows
HTML (form):
<form action=""> <div class="form-group"> <label>姓名:</label> <input id="name" type="text"> </div> <div class="form-group"> <label>手机号:</label> <input id="phone" type="text"> </div> <div class="form-group"> <label>身份证:</label> <input id="identity" type="text"> </div> <div class="form-group"> <label class="label-textarea">邮寄地址:</label> <textarea id="address"></textarea> </div> <p class="tip">请填写实名认证信息,以便领奖资料一经提交无法修改,请慎重填写!</p> <div class="btn-group"> <button class="btn btn-md btn-purple" type="reset">取消</button> <button class="btn btn-md btn-purple ml-20" id="submit" type="button">提交</button> </div> </form>
jQuery validation:
The test() method determines whether the regular expression content is matched in the string, and returns a boolean value (true / false)
// 验证中文名称 function isChinaName(name) { var pattern = /^[\u4E00-\u9FA5]{1,6}$/; return pattern.test(name); } // 验证手机号 function isPhoneNo(phone) { var pattern = /^1[34578]\d{9}$/; return pattern.test(phone); } // 验证身份证 function isCardNo(card) { var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; return pattern.test(card); } // 验证函数 function formValidate() { var str = ''; // 判断名称 if($.trim($('#name').val()).length == 0) { str += '名称没有输入\n'; $('#name').focus(); } else { if(isChinaName($.trim($('#name').val())) == false) { str += '名称不合法 '; $('#name').focus(); } } // 判断手机号码 if ($.trim($('#phone').val()).length == 0) { str += '手机号没有输入 '; $('#phone').focus(); } else { if(isPhoneNo($.trim($('#phone').val()) == false)) { str += '手机号码不正确 '; $('#phone').focus(); } } // 验证身份证 if($.trim($('#identity').val()).length == 0) { str += '身份证号码没有输入 '; $('#identity').focus(); } else { if(isCardNo($.trim($('#identity').val())) == false) { str += '身份证号不正确;\n'; $('#identity').focus(); } } // 验证地址 if($.trim($('#address').val()).length == 0) { str += '地址没有输入\n'; $('#address').focus(); } // 如果没有错误则提交 if(str != '') { alert(str); return false; } else { $('.auth-form').submit(); } } $('#submit').on('click', function() { formValidate(); });
I hope this article will be helpful to everyone learning jquery programming.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





1. After opening WeChat, click the search icon, enter WeChat team, and click the service below to enter. 2. After entering, click the self-service tool option in the lower left corner. 3. After clicking, in the options above, click the option of unblocking/appealing for auxiliary verification.

PHP8 is the latest version of PHP, bringing more convenience and functionality to programmers. This version has a special focus on security and performance, and one of the noteworthy new features is the addition of verification and signing capabilities. In this article, we'll take a closer look at these new features and their uses. Verification and signing are very important security concepts in computer science. They are often used to ensure that the data transmitted is complete and authentic. Verification and signatures become even more important when dealing with online transactions and sensitive information because if someone is able to tamper with the data, it could potentially

PHP regular expression verification: Number format detection When writing PHP programs, it is often necessary to verify the data entered by the user. One of the common verifications is to check whether the data conforms to the specified number format. In PHP, you can use regular expressions to achieve this kind of validation. This article will introduce how to use PHP regular expressions to verify number formats and provide specific code examples. First, let’s look at common number format validation requirements: Integers: only contain numbers 0-9, can start with a plus or minus sign, and do not contain decimal points. floating point

To validate email addresses in Golang using regular expressions, follow these steps: Use regexp.MustCompile to create a regular expression pattern that matches valid email address formats. Use the MatchString function to check whether a string matches a pattern. This pattern covers most valid email address formats, including: Local usernames can contain letters, numbers, and special characters: !.#$%&'*+/=?^_{|}~-`Domain names must contain at least One letter, followed by letters, numbers, or hyphens. The top-level domain (TLD) cannot be longer than 63 characters.

In Go, you can use regular expressions to match timestamps: compile a regular expression string, such as the one used to match ISO8601 timestamps: ^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ . Use the regexp.MatchString function to check if a string matches a regular expression.

Steam is a platform used by game enthusiasts. You can buy and purchase many games here. However, recently many users have been stuck in the mobile token verification interface when logging into Steam and cannot log in successfully. Faced with this Most users don't know how to solve this situation. It doesn't matter. Today's software tutorial is here to answer the questions for users. Friends in need can check out the operation methods. Steam mobile token error? Solution 1: For software problems, first find the steam software settings on the mobile phone, request assistance page, and confirm that the network using the device is running normally, click OK again, click Send SMS, you can receive the verification code on the mobile phone page, and you are done. Verify, resolve when processing a request

The method of using regular expressions to verify passwords in Go is as follows: Define a regular expression pattern that meets the minimum password requirements: at least 8 characters, including lowercase letters, uppercase letters, numbers, and special characters. Compile regular expression patterns using the MustCompile function from the regexp package. Use the MatchString method to test whether the input string matches a regular expression pattern.

The steps to detect URLs in Golang using regular expressions are as follows: Compile the regular expression pattern using regexp.MustCompile(pattern). Pattern needs to match protocol, hostname, port (optional), path (optional) and query parameters (optional). Use regexp.MatchString(pattern,url) to detect whether the URL matches the pattern.
