JS verify real name and ID number, mobile phone number simple example _javascript skills

Source: Internet
Author: User

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.

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.