Home Web Front-end JS Tutorial Summary of regular expressions for 15/18-digit ID number verification_regular expressions

Summary of regular expressions for 15/18-digit ID number verification_regular expressions

Jun 28, 2017 pm 01:43 PM
regular expression ID card

Need a simple regularexpression for verifying the ID number. I checked a lot from the Internet, but all have problems, so I just wrote one myself. The following article is mainly for Everyone shared the regular expression about 15/18-digit ID number verification. The article introduces it in very detail. Friends who need it can refer to it.

Preface

During the development process, it is often necessary to verify the validity of some input information. It is easiest to use regular expressions for verification. , the 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

Last two digits of year:

\d{2}

month:

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

Number of days:

(([0-2][1-9])|10 |20|30|31) Leap years cannot be prohibited 29+

three-digit sequential code:

\d{3}

two-digit sequential 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]$

Fifteen digits:

^[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

JSValidation 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

Summary

The above is the detailed content of Summary of regular expressions for 15/18-digit ID number verification_regular expressions. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

One ID card can open several Taobao stores One ID card can open several Taobao stores Oct 10, 2023 pm 01:51 PM

An ID card can only open one Taobao store. Sellers should abide by the regulations of the Taobao platform and do not try to use other people's ID cards to open multiple stores. Sellers can expand their business and increase sales by merging stores and opening branches. However, it should be noted that each branch needs to use an independent ID card for real-name authentication.

How to replace a string starting with something with php regular expression How to replace a string starting with something with php regular expression Mar 24, 2023 pm 02:57 PM

PHP regular expressions are a powerful tool for text processing and conversion. It can effectively manage text information by parsing text content and replacing or intercepting it according to specific patterns. Among them, a common application of regular expressions is to replace strings starting with specific characters. We will explain this as follows

How to match multiple words or strings using Golang regular expression? How to match multiple words or strings using Golang regular expression? May 31, 2024 am 10:32 AM

Golang regular expressions use the pipe character | to match multiple words or strings, separating each option as a logical OR expression. For example: matches "fox" or "dog": fox|dog matches "quick", "brown" or "lazy": (quick|brown|lazy) matches "Go", "Python" or "Java": Go|Python |Java matches words or 4-digit zip codes: ([a-zA

How to use regular expressions to remove Chinese characters in php How to use regular expressions to remove Chinese characters in php Mar 03, 2023 am 10:12 AM

How to remove Chinese in PHP using regular expressions: 1. Create a PHP sample file; 2. Define a string containing Chinese and English; 3. Use "preg_replace('/([\x80-\xff]*)/i', '',$a);" The regular method can remove Chinese characters from the query results.

How to use regular matching to remove html tags in php How to use regular matching to remove html tags in php Mar 21, 2023 pm 05:17 PM

In this article, we will learn how to remove HTML tags and extract plain text content from HTML strings using PHP regular expressions. To demonstrate how to remove HTML tags, let's first define a string containing HTML tags.

Will the mobile phone and ID card be demagnetized together? Will the mobile phone and ID card be demagnetized together? Aug 14, 2023 pm 02:33 PM

Mobile phones and ID cards will not be demagnetized together. The reasons are: 1. There are coils and chips integrated inside the ID card. Unlike traditional tapes, hard drives and other storage media, there are no magnetized substances; 2. The electromagnetic radiation of mobile phones is high. Frequency electromagnetic waves, with frequencies as high as hundreds of thousands to tens of millions of Hertz, have no ability to magnetize ID cards. The magnets in the mobile phone speakers will not have a demagnetizing effect on the ID card. We can safely put the ID card and mobile phone together, and pay attention to avoid damage to the ID card and protect its normal use so that it can serve us better.

How to solve Python expression syntax errors? How to solve Python expression syntax errors? Jun 24, 2023 pm 05:04 PM

Python, as a high-level programming language, is easy to learn and use. Once you need to write a Python program, you will inevitably encounter syntax errors, and expression syntax errors are a common one. In this article, we will discuss how to resolve expression syntax errors in Python. Expression syntax errors are one of the most common errors in Python, and they are usually caused by incorrect usage of syntax or missing necessary components. In Python, expressions usually consist of numbers, strings, variables, and operators. most common

Sharing tips on using PHP regular expressions to implement Chinese replacement function Sharing tips on using PHP regular expressions to implement Chinese replacement function Mar 24, 2024 pm 05:57 PM

Sharing tips on using PHP regular expressions to implement the Chinese replacement function. In web development, we often encounter situations where Chinese content needs to be replaced. As a popular server-side scripting language, PHP provides powerful regular expression functions, which can easily realize Chinese replacement. This article will share some techniques for using regular expressions to implement Chinese substitution in PHP, and provide specific code examples. 1. Use the preg_replace function to implement Chinese replacement. The preg_replace function in PHP can be used

See all articles