HongKong ID Card No. Validation
来源:互联网 发布:淘宝腿模招聘 编辑:程序博客网 时间:2024/05/01 22:47
for example: card no. = I1363861
1) if last_digit in ('0'..'9') check_sum = last_digit, if last_digit = 'A', check_sum = 10
else validation fail
check_sum = 1;
2) total = (ascii_value(first_digit) - 64) * 8
total = (ascii('I') - 64) * 8 = 72
3) for i = 2 to 7 { total += StrToInt(id[i]) * (9 - i); }
total = 72 + 1 * 7 + 3 * 6 + 6 * 5 + 3 * 4 + 8 * 3 + 6 * 2 = 175
4) remainder = total - (total / 11) * 11
remainder = 175 - (175 / 11) * 11 = 10
5) if remainder <> 0 { remainder = 11 - remainder }
remainder = 11 - 10 = 1
6) result = (check_sum == remainder ? true : false);
check_sum == remainder, return 1
--------------------------------------------------------------
if object_id('is_valid_hk_id') is not null
drop function is_valid_hk_id
go
create function is_valid_hk_id(@id_no nvarchar(10))
returns bit
as
begin
declare @check_sum int, @total int, @i int, @remainder int, @check_char char
declare @result bit
declare @id nvarchar(10)
set @id = upper(ltrim(rtrim(@id_no)))
set @id = replace(@id, '(', '')
set @id = replace(@id, ')', '')
if len(@id) <> 8
return 0
set @check_char = substring(@id, 8, 1)
if isnumeric(@check_char) = 1 set @check_sum = cast(@check_char as int)
else if @check_char = 'A' set @check_sum = 10
else return 0
if isnumeric(substring(@id, 2, 6)) = 0
return 0
set @total = (ascii(substring(@id, 1, 1)) - 64) * 8
set @i = 2
while @i <= 7
begin
set @total = @total + cast(substring(@id, @i, 1) as int) * (9 - @i)
set @i = @i + 1
end
set @remainder = @total - (@total / 11) * 11
if @remainder <> 0
set @remainder = 11 - @remainder
return case when @check_sum = @remainder then 1 else 0 end
end
go
- HongKong ID Card No. Validation
- ID card No.
- HongKong
- CERTIFICATION ID CARD
- HongKong Feel
- 错误信息: Ignored XML validation warning: No base URI; hope this SYSTEM id is absolute: http://www.springf
- Received CISSP certificate and ID card
- mono for Android no SD CARD solution
- Dummy output - No Sound Card Detected(转)
- #去掉“No SIM Card Installed”提示
- Validation of Chinese ID Numbers using JavaScript
- HongKong--big5编码
- HongKong二日初体验?
- card
- Card
- Mainland ID Card Number Generator and Check 程序
- XNA 4项目运行错误:No suitable graphics card found
- XNA工程编译时,报No suitable graphics card found
- 比较经典的程序
- spoolsv无法启动之修复
- 【j2nix】记住JSP中8个内置对象简单方法
- VC常见问题指南-1
- ASP.NET2.0 永恒密码之戒
- HongKong ID Card No. Validation
- 正则表达式30分钟入门教程
- 爱若和布若!
- 博士生的一点经验--转载
- php5中初次使用phplib小记----模板嵌套
- 开始学习Java和JSP
- 一个公交查询系统
- 客户端调用服务器端方法——ASP.NET AJAX(Atlas)、Anthem.NET和Ajax.NET Professional实现之小小比较
- ASP.NET2.0 遍历文件夹下所有图片