给我写一个身份证校验正则
时间: 2024-06-10 19:06:26 浏览: 16
表达式,可以校验18位和15位的身份证号码。
Sure, here is the regular expression to validate both 18-digit and 15-digit Chinese ID card numbers:
/^(\d{6})(19\d{2}|(20\d{2}))((0[1-9])|(1[0-2]))(([0-2][1-9])|(3[0-1]))(\d{3})(\d|x|X)?$|^(\d{6})(\d{2})((0[1-9])|(1[0-2]))(([0-2][1-9])|(3[0-1]))(\d{3})$/
Please note that this regular expression only checks if the format of the ID card is correct, but it does not guarantee that the ID card is valid.
相关问题
vue身份证校验正则
在Vue项目中,身份证号码的校验可以使用正则表达式来实现。下面是一个示例代码,其中包含了一个正则表达式,用于校验身份证号码的合法性:
```javascript
data() {
return {
rules: {
IDCard: [
{
required: true,
pattern: /^(([1-9][0-9]{5}(19|20)[0-9]{2}((0[1-9])|(1[0-2]))([0-2][1-9]|10|20|30|31)[0-9]{3}([0-9]|X|x))|([1-9][0-9]{5}[0-9]{2}((0[1-9])|(1[0-2]))([0-2][1-9]|10|20|30|31)[0-9]{3}))$/,
message: "请输入正确的身份证号",
trigger: "blur"
}
],
}
}
}
```
其中,正则表达式的含义是:身份证号码由18位数字或17位数字加上一个字母X组成,其中前6位表示出生地区,接下来8位表示出生日期,再接下来3位表示出生顺序,最后一位是校验码。这个正则表达式可以校验身份证号码的格式是否正确,但并不能保证身份证号码的真实性。
身份证校验正则表达式
身份证校验的正则表达式可以使用以下代码实现:
```java
private static final String identityRegix = "^((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|[7-9]1)\\d{4}(19|20|21)\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
```
这个正则表达式可以用来校验身份证号码的格式是否正确。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)