代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
JS
】
身份证号验证(严格)
作者:
瑜涵
/ 发布于
2015/2/15
/
583
!function(win){ var _idcard,_gender,_birthday,_address,_msg,_code; var _coefficient = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1]; var _verify_code = ['1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2']; var _base_code = []; var _date_verify = {"01":31,"02":null,"03":31,"04":30,"05":31,"06":30,"07":31,"08":31,"09":30,"10":31,"11":30,"12":31}; var _area_code = ["11","12","13","14","15","21","22" ,"23","31","32","33","34","35","36","37","41","42","43","44" ,"45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"]; var _gender_code = ['\u5973','\u7537']; var _msg_code = ['\u8f93\u5165\u7684\u8eab\u4efd\u8bc1\u53f7\u4e0d\u662f15\u4f4d\u548c18\u4f4d\u7684','\u65e0\u6548\u7684\u8eab\u4efd\u8bc1\u53f7','\u8eab\u4efd\u8bc1\u5408\u6cd5','\u4e0d\u662f15\u4f4d\u8eab\u4efd\u8bc1\u5417','15\u4f4d\u8eab\u4efd\u8bc1\u53f7']; var idcard = function(){}; idcard.prototype = { verify:function(idcard){ if(idcard.length == 15){ return this.to18(idcard); } _idcard = idcard; parse(); return _return(); }, to18:function(idcard){ _idcard = idcard; _15to18(); return _return(); } } function _return(){ if(typeof _code_area == 'undefined') _code_area = {}; // var _code_area = _code_area ||{}; try{ _address = _code_area[_idcard.substring(0,6)]; }catch(e){ _address = '\u672a\u77e5\u533a\u57df'; } return { gender:_gender, birthday:_birthday, msg:_msg, code:_code, address:_address, idcard:_idcard } } function _15to18(){ if(_idcard.length != 15){ return false; } _idcard = _idcard.substring(0,6)+"19"+_idcard.substring(6); if(!_verify_area()) return; if(!_verify_birthday()) return; if(!_verify_base_code()) return; var remaining = _get_verify_code(); _idcard = _idcard+remaining; _get_gender(); _code = 0; _msg = _msg_code[4]; } function _verify_birthday(){ _msg = _msg_code[1]; var _year,_month,_day; _year = _idcard.substring(6,10); _month= _idcard.substring(10,12); _day = _idcard.substring(12,14); if(!(_month in _date_verify)){ return false; } if(+_day<1){ return false; } if(_date_verify[_month] != null && (+_day>_date_verify[_month])){ return false; } if(_date_verify[_month] == null){ if((_year%4==0&&_year%100!=0)||(_year%400==0) && _day>29){ return false; } else{ if (_day>28) { return false; }; } } _birthday = _year+'-'+_month+'-'+_day; return true; } function _verify_length(){ _msg = _msg_code[0]; if(_idcard.length!=18 && _idcard.length!=15){ return false; } return true; } function _verify_area(){ var _area; _msg = _msg_code[1]; _area = _idcard.substring(0,2); for(var i=0;i<_area_code.length;i++){ if(_area_code[i]==_area){ return true; } } return false; } function _get_gender(){ var _sex_code = _base_code[16]; var _remaining = _sex_code%2; _gender = _gender_code[_remaining]; } function _verify_base_code(){ var _eightcardid = _idcard.substring(0,17); _msg = _msg_code[1]; try{ for(var i=0;i<17;i++){ var _k = _idcard.substring(i,i+1); _base_code.push(+_k); } }catch(e){ return false; } return true; } function _get_verify_code(){ _msg = _msg_code[1]; var _remaining = 0; var _sum = 0; for(var i=0;i<17;i++){ _sum += _base_code[i]*_coefficient[i]; } remaining = _sum % 11; return _verify_code[remaining]; } function _verify(){ var remaining = _get_verify_code(); var _verify_ = _idcard.substring(17).toLowerCase(); if (remaining != _verify_) { return false; }; return true; } function parse(){ _code = 1; if(!_verify_length()) return; if(!_verify_area()) return; if(!_verify_birthday()) return; if(!_verify_base_code()) return; if(!_verify()) return; _get_gender(); _code = 0; _msg = _msg_code[2]; } win.idcard = new idcard(); }(window); //示例: idcard.verify("xxxxxxxxxxxxxxxxxx"); idcard.to18("xxxxxxxxxxxxxxxxxx");
试试其它关键字
身份证号
同语言下
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
瑜涵
贡献的其它代码
(
4
)
.
身份证号验证(严格)
.
form表单数据转换为Object对象
.
银行卡号校验
.
国内手机号码匹配(2015年)
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3