身份證校驗,檢查身份證號碼輸入是否正確

2021-09-23 19:27:40 字數 4287 閱讀 5936

中國廣東省

深圳市龍華新區民治街道溪山美地

518131

+86 13113668890

+86 755 29812080

文件始創於2010-11-18

文件出處:

$date: 2013-04-10 15:03:49 +0800 (wed, 10 apr 2013) $

我的系列文件

netkiller architect 手札

netkiller developer 手札

netkiller php 手札

netkiller python 手札

netkiller testing 手札

netkiller cryptography 手札

netkiller linux 手札

netkiller centos 手札

netkiller freebsd 手札

netkiller security 手札

netkiller version 手札

netkiller web 手札

netkiller monitoring 手札

netkiller storage 手札

netkiller mail 手札

netkiller shell 手札

netkiller network 手札

netkiller database 手札

netkiller postgresql 手札

netkiller mysql 手札

netkiller nosql 手札

netkiller ldap 手札

netkiller cisco ios 手札

netkiller h3c 手札

netkiller ********** 手札

netkiller docbook 手札

netkiller 開源軟體 手札

該函式能夠檢查身份證號碼是否正確

create definer=`neo`@`%` function `check_id_number`(`idnumber` char(18))

returns enum('true','false')

language sql

not deterministic

no sql

sql security definer

comment ''

begin

declare status enum('true','false') default 'false';

declare verify char(1);

declare sigma int;

declare remainder int;

if length(idnumber) = 18 then

set sigma = cast(substring(idnumber,1,1) as unsigned) * 7

+cast(substring(idnumber,2,1) as unsigned) * 9

+cast(substring(idnumber,3,1) as unsigned) * 10

+cast(substring(idnumber,4,1) as unsigned) * 5

+cast(substring(idnumber,5,1) as unsigned) * 8

+cast(substring(idnumber,6,1) as unsigned) * 4

+cast(substring(idnumber,7,1) as unsigned) * 2

+cast(substring(idnumber,8,1) as unsigned) * 1

+cast(substring(idnumber,9,1) as unsigned) * 6

+cast(substring(idnumber,10,1) as unsigned) * 3

+cast(substring(idnumber,11,1) as unsigned) * 7

+cast(substring(idnumber,12,1) as unsigned) * 9

+cast(substring(idnumber,13,1) as unsigned) * 10

+cast(substring(idnumber,14,1) as unsigned) * 5

+cast(substring(idnumber,15,1) as unsigned) * 8

+cast(substring(idnumber,16,1) as unsigned) * 4

+cast(substring(idnumber,17,1) as unsigned) * 2;

set remainder = mod(sigma,11);

set verify = (case remainder

when 0 then '1' when 1 then '0' when 2 then 'x' when 3 then '9'

when 4 then '8' when 5 then '7' when 6 then '6' when 7 then '5'

when 8 then '4' when 9 then '3' when 10 then '2' else '/' end

);end if;

if right(idnumber,1) = verify then

set status = 'true';

end if;

return status;

end

首先我們使用正確身份證號碼進行測試,返回true

mysql> select check_id_number('330702198003090915');

+---------------------------------------+

| check_id_number('330702198003090915') |

+---------------------------------------+

| true |

+---------------------------------------+

1 row in set (0.01 sec)

長度不符合18位直接返回false.

mysql> select check_id_number('33070219800309');

+-----------------------------------+

| check_id_number('33070219800309') |

+-----------------------------------+

| false |

+-----------------------------------+

1 row in set (0.00 sec)

mysql> select check_id_number('33070219800309091457889');

+--------------------------------------------+

| check_id_number('33070219800309091457889') |

+--------------------------------------------+

| false |

+--------------------------------------------+

1 row in set, 1 warning (0.00 sec)

隨便改譯為數,校驗失敗返回 false

mysql> select check_id_number('330702198003090914');

+---------------------------------------+

| check_id_number('330702198003090914') |

+---------------------------------------+

| false |

+---------------------------------------+

1 row in set (0.00 sec)

身份證號碼校驗

中國居民身份證號碼編碼規則 中國居民身份證校驗碼演算法 都包含 author liuwei date 2020 11 19 身份證校驗工具 public class idnumutil 定義判別使用者身份證號的正規表示式 15位或者18位,最後一位可以為字母 string regularexpres...

身份證號碼

每乙個人自出生後都會有乙個身份證號碼。根據我國有關部門規定,公民身份號碼是特徵組合碼,由十七位數字本體碼和一位數字校驗碼組成。排列順序從左至右依次為 六位數字位址碼,八位數字出生日期碼,三位數字順序碼和一位數字校驗碼。居民身份證是國家法定的證明公民個人身份的有效證件。例如 對於身份證號碼330719...

Oracle 身份證號碼校驗

今天來了身份證校驗的需求,想在oracle中校驗後將錯誤資料查詢出來。於是我在網上查到了身份證校驗的oracle函式。但是發現一些正確的身份證號也未校驗通過!後來經過千辛萬苦的努力終於發現了,網上給的函式中判斷是否是閏年的 substrb 函式應該從第7為開始擷取,而不是第6位!還有要注意最後一位校...