Recent projects used in the need to call the real-name authentication interface, real-name authentication interface price compared to SMS is not a bit higher than a few cents, so that the conditions of the call authentication is strict, so use to JS verify the true name and JS authentication ID number.
Get to the point.
1.js Verify real name
JS Verify the real name, is used to match the Unicode characters, and the Chinese name is generally 2-4, so repeat the match {2,4} times
var regname =/^[\u4e00-\u9fa5]{2,4}$/;
if (!regname.test (name)) {
alert (' True name filled in error ');
return false;
}
2.js Authentication ID Number
JS Verification ID number, China's identity card number, a generation of ID number is 15 digits, the second generation ID cards are 18 digits, the last one in addition to a check digit may be ' x ' or ' x ', so there are four possibilities: a.15 digit b.18 digit c.17 digit number, 18th digit is ' x ' d.17 Digit, 18th digit is ' x '
var Regidno =/(^\d{15}$) | (^\d{18}$) | (^\d{17} (\d| X|X) $)/;
if (!regidno.test (Idno)) {
alert (' identity card number filled in error ');
return false;
}
Detailed version of ID card verification:
Http://www.jb51.net/article/88771.htm
3.js verification of mobile phone number
China's mobile phone number in addition to the area code (+86), are 11 digits and the first letter must be 1, the second is not necessarily, but so far there is no 1 and 2
var Mobileregex =/^ ((1[3456789][0-9]{1}) | ( 15[0-9]{1})) +\d{8}) $/;
if (mobileregex.test (phone)) {
alert (' Phone number is correct ');
} else{
alert (' phone number entered incorrectly ');
}
This JS verification of the real name and identity card number, mobile phone number is a simple example is a small series to share all the content, I hope to give you a reference, but also hope that we support the cloud habitat community.