- function iscardno (card)
- {
- // The ID number is 15 or 18 bits, 15 digits are all digits, 18 bits is the first 17 digits, the last one is the check digit, possibly the number or character x
- var reg = /(^\d{15}$) | (^\d{18}$) | (^\d{17} (\d| X|X) $)/;
- if (reg.test (card) === false)
- {
- alert ( "ID not legally entered");
- return false;
-    }  
- }
Recent projects with the need to call the real-name authentication interface, real-name authentication interface price is not a few cents higher than the text message, so call the real-names authentication conditions to strictly check, so the use of JS to verify the real title and JS Authentication ID number.
Go to the Chase
JS to verify the real name, is to use the Unicode character to match, and the Chinese name length is generally 2-4, so repeat the match {2,4} times
1.js Verify real name
- var regname =/^[\u4e00-\u9fa5]{2,4}$/;
- if (!regname.test (name)) {
- Alert (' real name is incorrect ');
- return false;
- }
JS Authentication ID number, China's ID number, a generation of identity card number is 15 digits, the second-generation ID card is 18-bit, the last check digit in addition to may be the number may also be ' x ' or ' x ', so there are four possibilities: a.15 bit number b.18 digit c.17 digit, 18th bit is ' X ' d.17 digits, the 18th digit is ' x '
2.js Authentication ID Number
- var Regidno =/(^\d{15}$) | ( ^\d{18}$) | (^\d{} (\d| X|X) $)/;
- if (!regidno.test (Idno)) {
- Alert (' ID number is incorrect ');
- return false;
- }
JS Regular expression Verification ID number