01.
<input name=
"id_card_txt"
type=
"text"
id=
"id_card_txt"
onKeyPress=
"if (event.keyCode < 48 || event.keyCode > 57 ){event.returnValue = false;}"
maxlength=
"13"
>
02.
<input type=
"submit"
name=
"Submit"
value=
"Check id card"
onClick=
"id_card(document.getElementById('id_card_txt'))"
>
03.
04.
<script>
05.
function
check_idcard(idcard){
06.
if
(idcard.value ==
""
){
return
false;}
07.
if
(idcard.length < 13){
return
false;}
08.
09.
var
num =
str_split
(idcard);
10.
var
sum = 0;
11.
var
total = 0;
12.
var
digi = 13;
13.
14.
for
(i=0;i<12;i++){
15.
sum = sum + (num[i] * digi);
16.
digi--;
17.
}
18.
total = ((11 - (sum % 11)) % 10);
19.
20.
if
(total == num[12]){
21.
return
true;
22.
}
else
{
23.
return
false;
24.
}
25.
}
26.
27.
28.
function
str_split
( f_string, f_split_length){
29.
f_string +=
''
;
30.
if
(f_split_length == undefined) {
31.
f_split_length = 1;
32.
}
33.
if
(f_split_length > 0){
34.
var
result = [];
35.
while
(f_string.length > f_split_length) {
36.
result[result.length] = f_string.substring(0, f_split_length);
37.
f_string = f_string.substring(f_split_length);
38.
}
39.
result[result.length] = f_string;
40.
return
result;
41.
}
42.
return
false;
43.
}
44.
45.
function
id_card(id){
46.
if
(check_idcard(id.value)){
47.
alert(
"ID Card Completed."
);
48.
}
else
{
49.
alert(
"ID Card Error ?\nPlease Tye Again"
);
50.
id.value =
""
;
51.
id.focus();
52.
}
53.
}
54.
</script>