Home > Web Front-end > JS Tutorial > body text

What are the regular writing methods for 15/18-digit ID number verification?

php中世界最好的语言
Release: 2018-03-29 16:52:14
Original
3890 people have browsed it

This time I will bring you what are the regular writing methods for 15/18-digit ID card number verification, what are the precautions, and the following are practical cases, one Get up and take a look.

Preface

During the development process, it is often necessary to verify the validity of some input information, using regular expressions Verification is the simplest and most efficient way. Let’s take a look at the regular expression for 15/18-digit ID number verification.

Introduction

##xxxxxx yyyy MM dd 375 0 18 digits

xxxxxx yy MM dd 75 0 15 digits

Region:

[1-9]\d{5}

The top two in the year:

(18|19|([23]\d) )            1800-2399 The last two digits of the year

:

\d{2}

Month:

((0[1-9]) | (10 | 11 | 12)) ## Day:

([[0-2] [1-9]) | 10 | 20 | 30 | 31)

不Forbidden 29+ Three-digit sequence code:

\d{3}

Two-digit sequence code:

\d{2}

Check code:

[0-9Xx]

Regular expressionEighteen digits:

^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))( ([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$

Fifteenth digit:

^[ 1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20| 30|31)\d{2}$

Total:(

^[1-9]\ d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1- 9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9] )|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$

)

Simple JS verification example

function isCardNo(card) 
{ 
// 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X 
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
if(reg.test(card) === false) 
{ 
alert("身份证输入不合法"); 
return false; 
} 
}
Copy after login

I believe you have mastered the method after reading the case in this article, please pay attention for more exciting things Other related articles on php Chinese website!

Recommended reading:

Analysis of the principles and syntax of JS regularity


Pictures of using regular multi-line mode and single-line mode Detailed text explanation

The above is the detailed content of What are the regular writing methods for 15/18-digit ID number verification?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!