Home >Web Front-end >JS Tutorial >Summary of regular expressions for 15/18-digit ID number verification_regular expressions
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 digitsxxxxxx yy MM dd 75 0 15 digitsRegion:[1-9]\d{5}
(18|19|([23] \d)) 1800-2399
\d{2}
((0[1-9])|(10|11|12))
(([0-2][1-9])|10 |20|30|31) Leap years cannot be prohibited 29+
\d{3}
\d{2}
[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}(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}$
)JSValidation examplefunction 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;
}
}
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!