<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN">
<html>
<head>
Check <title> ID </ title>
<script>
/ / Check the ID card function checkIdcard (idcard) (
var Errors = new Array (
"true",
"Right-digit ID number!"
"Identity card number or date of birth is out of range to contain illegal characters!"
"Identity card number checksum error!"
"ID cards illegal!"
);
var area = (11: "Beijing", 12: "Tianjin", 13: "Hebei", 14: "Shanxi", 15: "Inner Mongolia", 21: "Liaoning", 22: "Jilin", 23: "Heilongjiang "31:" Shanghai ", 32:" Jiangsu ", 33:" Zhejiang ", 34:" Anhui ", 35:" Fujian ", 36:" Jiangxi ", 37:" Shandong ", 41:" Henan ", 42: "Hubei", 43: "Hunan", 44: "Guangdong", 45: "Guangxi", 46: "Hainan", 50: "Chongqing", 51: "Sichuan", 52: "Guizhou", 53: "Yunnan", 54: "Tibet", 61: "Shaanxi", 62: "Gansu", 63: "Qinghai", 64: "Ningxia", 65: "Xinjiang", 71: "Taiwan", 81: "Hong Kong "82:" Macao ", 91:" abroad ")
var idcard, Y, JYM;
var S, M;
var idcard_array = new Array ();
idcard_array = idcard.split ("");
/ / Inspection if (area [parseInt (idcard.substr (0, 2))] == null) return Errors [4];
/ / Identification number and format of the median test switch (idcard.length) (
case 15:
if ((parseInt (idcard.substr (6, 2)) + 1900)% 4 == 0 | | ((parseInt (idcard.substr (6, 2)) + 1900)% 100 == 0 & & (parseInt (idcard . substr (6, 2)) + 1900)% 4 == 0)) (
ereg = / ^ [1-9] [0-9] (5) [0-9] (2) ((01 | 03 | 05 | 07 | 08 | 10 | 12) (0 [1-9] | [ 1-2] [0-9] | 3 [0-1]) | (04 | 06 | 09 | 11) (0 [1-9] | [1-2] [0-9] | 30) | 02 (0 [1-9] | [1-2] [0-9])) [0-9] (3) $ /;
/ / Test the legality of the date of birth) else (
ereg = / ^ [1-9] [0-9] (5) [0-9] (2) ((01 | 03 | 05 | 07 | 08 | 10 | 12) (0 [1-9] | [ 1-2] [0-9] | 3 [0-1]) | (04 | 06 | 09 | 11) (0 [1-9] | [1-2] [0-9] | 30) | 02 (0 [1-9] | 1 [0-9] | 2 [0-8])) [0-9] (3) $ /;
/ / Test the legality of the date of birth)
if (ereg.test (idcard)) return Errors [0];
else return Errors [2];
break;
case 18:
/ / 18 identification number detecting / / date of birth to check the legality / / leap year date: ((01 | 03 | 05 | 07 | 08 | 10 | 12) (0 [1-9] | [1-2] [0-9] | 3 [0-1]) | (04 | 06 | 09 | 11) (0 [1-9] | [1-2] [0-9] | 30) | 02 (0 [1 -9] | [1-2] [0-9]))
/ / Ping date: ((01 | 03 | 05 | 07 | 08 | 10 | 12) (0 [1-9] | [1-2] [0-9] | 3 [0-1]) | ( 04 | 06 | 09 | 11) (0 [1-9] | [1-2] [0-9] | 30) | 02 (0 [1-9] | 1 [0-9] | 2 [0 -- 8]))
if (parseInt (idcard.substr (6, 4))% 4 == 0 | | (parseInt (idcard.substr (6, 4))% 100 == 0 & & parseInt (idcard.substr (6, 4))% 4 == 0)) (
ereg = / ^ [1-9] [0-9] (5) (19 | 20) [0-9] (2) ((01 | 03 | 05 | 07 | 08 | 10 | 12) (0 [1 -9] | [1-2] [0-9] | 3 [0-1]) | (04 | 06 | 09 | 11) (0 [1-9] | [1-2] [0-9] | 30) | 02 (0 [1-9] | [1-2] [0-9])) [0-9] (3) [0-9Xx] $ /;
/ / Leap year date of birth of the legitimacy of the regular expression) else (
ereg = / ^ [1-9] [0-9] (5) (19 | 20) [0-9] (2) ((01 | 03 | 05 | 07 | 08 | 10 | 12) (0 [1 -9] | [1-2] [0-9] | 3 [0-1]) | (04 | 06 | 09 | 11) (0 [1-9] | [1-2] [0-9] | 30) | 02 (0 [1-9] | 1 [0-9] | 2 [0-8])) [0-9] (3) [0-9Xx] $ /;
/ / Average year's date of birth to the legitimacy of the regular expression)
if (ereg.test (idcard)) (/ / test the legality of the date of birth / / calculating the parity bit S = (parseInt (idcard_array [0]) + parseInt (idcard_array [10])) * 7
+ (ParseInt (idcard_array [1]) + parseInt (idcard_array [11])) * 9
+ (ParseInt (idcard_array [2]) + parseInt (idcard_array [12])) * 10
+ (ParseInt (idcard_array [3]) + parseInt (idcard_array [13])) * 5
+ (ParseInt (idcard_array [4]) + parseInt (idcard_array [14])) * 8
+ (ParseInt (idcard_array [5]) + parseInt (idcard_array [15])) * 4
+ (ParseInt (idcard_array [6]) + parseInt (idcard_array [16])) * 2
+ ParseInt (idcard_array [7]) * 1
+ ParseInt (idcard_array [8]) * 6
+ ParseInt (idcard_array [9]) * 3;
Y = S% 11;
M = "F";
JYM = "10X98765432";
M = JYM.substr (Y, 1);
/ / Determine the parity bit if (M == idcard_array [17]. ToUpperCase ()) return Errors [0]; / / the parity bit ID detection else return Errors [3];
)
else return Errors [2];
break;
default:
return Errors [1];
break;
)
)
function check ()
(
var card = document.getElementById ( "card");
var result = checkIdcard (card.value);
if (result == 'true')
document.getElementById ( "info"). innerHTML = "<font color='blue'> check the correct identity </ font>";
else
document.getElementById ( "info"). innerHTML = "<font color='red'>" + result + "</ font>";
)
</ script>
</ head>
<body>
ID: <input type="text" size="20"> <input type="button" value="校验身份证"> <br> <br>
<div> </ div>
</ body>
</ html>