Js verifies the real name and ID card number, a simple example of the mobile phone number, and the real name of js

Source: Internet
Author: User

Js verifies the real name and ID card number, a simple example of the mobile phone number, and the real name of js

In recent projects, real-name authentication interfaces need to be called. The price of real-name authentication interfaces is not a fraction of the money compared to that of Short Messages. Therefore, the conditions for calling real-name authentication must be strictly controlled, therefore, JavaScript is used to verify the real name and js verification ID card number.

Enter the subject

1. Verify the real name in js

Javascript verifies the real name, which is a unicode Character for matching, while the Chinese name length is generally 2-4, so repeated match {2, 4} Times

Var regName =/^ [\ u4e00-\ u9fa5] {2, 4} $/; if (! RegName. test (name) {alert ('incorrect real name filling '); return false ;}

2. Verify the ID card number in js

ID card number verified by js, ID card number of China, ID card number of the first generation is 15 digits, ID card number of the second generation is 18 digits, the last digit may be either 'X' or 'X', so there are four possibilities: a.15 digit B .18 digit c.17 digit, the fifth digit is 'x' d.17 digits, and the fifth digit is 'x'

Var regIdNo =/(^ \ d {15} $) | (^ \ d {18} $) | (^ \ d {17} (\ d | X | x) $)/; if (! RegIdNo. test (idNo) {alert ('Id card number filled incorrectly '); return false ;}

Detailed version ID card verification:

Http://www.bkjia.com/article/88771.htm

3. Verify the mobile phone number in js

In addition to the area code (+ 86), China's mobile phone numbers are all 11 digits and the first letter must be 1. The second digit is not necessarily, but so far there are no numbers 1 and 2.

Var assumeregex =/^ (1 [3456789] [0-9] {1}) | (15 [0-9] {1 })) + \ d {8}) $/; if (assumeregex. test (phone) {alert ('mobile phone number is correct ');} else {alert ('mobile phone number entered incorrectly ');}

The above JavaScript code verifies the real name and ID card number. A simple example of the mobile phone number is all the content that I have shared with you. I hope you can provide a reference and support for the customer's house.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.