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.