PHP 验证香港身份证ID号

/**
check hk idcard
$id = "K548653A";
$xx= check_hkid($id);
var_dump($xx);
**/
function check_hkid($id)
{
if (!preg_match("/^[a-zA-Z][0-9]{6}[0-9aA]$/", $id)) {
return false;
}
$mul = 8;
$sum = (ord(strtoupper($id))-64) * $mul;
while($mul>1) {
$sum += intval(substr($id, 8 - $mul, 1)) * $mul;
$mul --;
}
$chksum = dechex(strval(11-($sum % 11)));//dec to hex
if ($chksum == ‘b‘) {
$chksum = 0;
}
return $chksum == strtolower(substr($id, 7, 1));
}

JS
private function check_hkid(id) {
if (!id.match(/^[a-zA-Z][0-9]{6}[0-9aA]$/)) return false;
var mul = 8, sum = (id.toUpperCase().charCodeAt()-64) * mul--;
while (mul>1) sum += parseInt(id.substr(8-mul, 1)) * mul--;
var chksum = (11-(sum % 11)).toString(16);
if (chksum == "b") chksum = "0";
return chksum == id.substr(7,1).toLowerCase();
}

时间: 2024-08-08 17:40:11

PHP 验证香港身份证ID号的相关文章

javascript验证香港身份证

1 var assert = require('assert'); 2 describe('test', function() { 3 it('coc', function() { 4 var testCard01 = checkHKIDcard("AB987654(2)"); 5 assert(testCard01, true); 6 7 var testCard02 = checkHKIDcard("G123456(A)"); 8 assert.equal(te

删除除了 id 号不同,其他都相同的学生冗余信息

删除除了 id 号不同,其他都相同的学生冗余信息2.学生表 如下:id 号 学号 姓名 课程编号 课程名称 分数1 2005001 张三 0001 数学 692 2005002 李四 0001 数学 893 2005001 张三 0001 数学 69 create table student2(id int auto_increment primary key,code varchar(20),name varchar(20));insert into student2 values(null,

*RC523读身份证ID

最近用RC523读身份证ID,经过几天摸索和参考网上资料,终于所成功了,特发此贴给有需要的朋友,但愿能少走弯路 RC523 寄存器配置:        RcSetReg(JREG_TXASK, 0x00);         RcSetReg(JREG_CONTROL, 0x10);         RcSetReg(JREG_TXMODE, 0x03);         RcSetReg(JREG_RXMODE, 0x0B);         RcSetReg(JREG_TYPEB, 0x03)

VC 为静态控件添加事件(修改ID号以后添加事件)

操作系统:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为静态控件添加事件,如:STATIC.Picture Control等等 有时候我们找到一个图片,为对话框背景添加了图片,我们需要在某个位置令其可以单击,如下两图所示: 首先:修改静态控件属性Notify 为True,修改控件ID 号,一定要修改,在这里我改为IDC_RIGHT,右键为静态控件添加左键单击事件,在这里我在代码里面添加了弹出消息对话框以作测试,效果如下: 虽然不是动态的按钮,但是效果蛮不错的. h

Android安卓获取ID号,本机号码,手机型号,系统版本

Mark一下 public void Msg1(String str) { Toast toast = new Toast(this); Toast toast1 = toast.makeText(this, str, Toast.LENGTH_LONG); toast1.show(); } //获取ID号 final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPH

使用js代码获得文章的id号

使用js代码获得文章路径的id号 很多cms都是使用id号串联文章,那么怎样用js获得id号呢? 经过一天的研究,终于有了成果,代码如下: <script> var url = location.href; url = url.match(/\/(\d*).html/); document.write(url[1]); </script> 该代码可以使用另外的js引用. 例如网址:http://www.lc13.cn/yulu/haoju/825.html 能截获/开始,html结

现代浏览器原生js获取id号方法

<div id="tests" class="a b c" style="color:#f00">123</div> var test = tests.firstChild.nodeValue; tests = tests.childNodes[0]; tests.insertData(0,789);//从前插入789 var t2 = document.querySelector("#tests");

magento获取当前栏目ID号与栏目名称函数

Magento获取当前栏目ID:$_cat= new Mage_Catalog_Block_Navigation();$curent_cat= $_cat->getCurrentCategory();$curent_cat_id= $curent_cat->getId(); 或者Mage::registry('current_category')->getEntityId() Magento获取当前栏目名称: $category= Mage::registry('current_cate

Linux进程ID号--Linux进程的管理与调度(三)

日期 内核版本 架构 作者 GitHub CSDN 2016-05-12 Linux-4.5 X86 & arm gatieme LinuxDeviceDrivers Linux-进程管理与调度 Linux 内核使用 task_struct 数据结构来关联所有与进程有关的数据和结构,Linux 内核所有涉及到进程和程序的所有算法都是围绕该数据结构建立的,是内核中最重要的数据结构之一. 该数据结构在内核文件include/linux/sched.h中定义,在目前最新的Linux-4.5(截至目前的