updated 更新身份证解析算法

This commit is contained in:
PASSER-BY 2024-03-27 22:58:01 +08:00
parent d8ebab9496
commit 02f6799205
3 changed files with 28 additions and 23 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2016 Haole Zheng Copyright (c) 2024 Haole Zheng
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -76,11 +76,14 @@
</div> </div>
</div> </div>
<div id="idcard" class="box"> <div id="idcard" class="box">
<div class="c-hd"><span class="title">身份证号码查询</span></div> <div class="c-hd">
<span class="title">身份证号码查询</span>
<a class="more" href="https://passer-by.com/idcard/" target="_blank">中国身份证号码解析 &gt;</a>
</div>
<div class="c-bd"> <div class="c-bd">
<form action="" method="post"> <form action="" method="post">
<p> <p>
<input type="text" name="id" value="" maxlength="18" placeholder="请输入身份证号码"/> <input type="search" name="id" value="" maxlength="18" placeholder="请输入身份证号码" autocomplete="off"/>
<button class="btn">查询</button> <button class="btn">查询</button>
</p> </p>
</form> </form>
@ -137,6 +140,7 @@
<script type="text/javascript" src="https://jquerywidget.com/code/jquery.citys.js"></script> <script type="text/javascript" src="https://jquerywidget.com/code/jquery.citys.js"></script>
<script type="text/javascript" src="https://jquerywidget.com/code/jquery.suggestion.js"></script> <script type="text/javascript" src="https://jquerywidget.com/code/jquery.suggestion.js"></script>
<script type="text/javascript" src="static/script/locationSearch.js"></script> <script type="text/javascript" src="static/script/locationSearch.js"></script>
<script type="text/javascript" src="https://passer-by.com/idcard/dist/idcard.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
(function(){ (function(){
var listMap = {}; var listMap = {};
@ -271,29 +275,29 @@
var $idcard = $('#idcard'); var $idcard = $('#idcard');
$idcard.find('form').on('submit',function(){ $idcard.find('form').on('submit',function(){
var $this = $(this); var $this = $(this);
var value = $this.find('input[type="text"]').val(); var id = $this.find('input[name="id"]').val();
var code = value.substr(0,6); var result = idcard(id);
var date = value.substr(6,8); if(!result){
var sex = value.charAt(16)%2?'男':'女';
if(!value.match(/^\d{17}[0-9xX]$/)){
alert('身份证号码格式错误!'); alert('身份证号码格式错误!');
}else{ }else{
newAddress = ''; var newAddress = '';
if(diffMap[code]){ if(diffMap[code]){
newAddress = '<tr>\ newAddress = `<tr>
<td class="th"><span>现所属地</span></td>\ <td class="th"><span>现所属地</span></td>
<td>'+diffMap[code].map(function(value){return '<p>'+getName(value)+'</p>';})+'</td>\ <td>${diffMap[code].map(function(value){return '<p>'+getName(value)+'</p>';})}</td>
</tr>'; </tr>`;
} }
$idcard.find('.table-inner').html('<table>\ $idcard.find('.table-inner').html(`<table>
<tbody>\ <tbody>
<tr><td class="th" width="25%">首次签发地</td><td>'+getName(code)+'</td></tr>\ <tr><td class="th" width="25%">证件类型</td><td>${result['type']}</td></tr>
'+newAddress+'\ <tr><td class="th">国籍</td><td>${result['country']}</td></tr>
<tr><td class="th">出生日期</td><td>'+date.replace(/(\d{4})(\d{2})(\d{2})/,'$1年$2月$3日')+'</td></tr>\ <tr><td class="th">首次签发地</td><td>${result['sign']}</td></tr>
<tr><td class="th">性别</td><td>'+sex+'</td></tr>\ ${newAddress}
<tr><td class="th">有效性</td><td>'+(isValid(value)?'<span class="text-green">有效</span>':'<span class="text-red">无效</span>')+'</td></tr>\ <tr><td class="th">出生日期</td><td>${result['birthday'].replace(/(\d{4})(\d{2})(\d{2})/,'$1年$2月$3日')}</td></tr>
</tbody>\ <tr><td class="th">性别</td><td>${result['sex']}</td></tr>
</table>'); <tr><td class="th">有效性</td><td>${(result['isValid']?'<span class="text-green">有效</span>':'<span class="text-red">无效</span>')}</td></tr>
</tbody>
</table>`);
} }
return false; return false;
}); });

View File

@ -95,6 +95,7 @@ a:hover{
margin-bottom: 75px; margin-bottom: 75px;
} }
.mod-panel .hd{ .mod-panel .hd{
min-height: 150px;
padding: 35px 0; padding: 35px 0;
line-height: 22px; line-height: 22px;
} }
@ -181,7 +182,7 @@ a:hover{
border-radius: 4px; border-radius: 4px;
outline: none; outline: none;
} }
.mod-panel .bd input[type="text"]{ .mod-panel .bd input[type="text"],.mod-panel .bd input[type="search"]{
width: 240px; width: 240px;
height: 32px; height: 32px;
padding: 0 10px; padding: 0 10px;