1
2
3 function chkresno(resno) {
4
5
6 fmt = /^\d{6}-[1234]\d{6}$/;
7 if(!fmt.test(resno)) {
8 alert("잘못된 주민등록번호입니다.");
9 return;
10 }
11
12
13 birthYear = (resno.charAt(7) <= "2") ? "19" : "20";
14 birthYear += resno.substr(0, 2);
15 birthMonth = resno.substr(2, 2) - 1;
16 birthDate = resno.substr(4, 2);
17 birth = new Date(birthYear, birthMonth, birthDate);
18
19 if(birth.getYear() % 100 != resno.substr(0, 2) || birth.getMonth() != birthMonth ||
20 birth.getDate() != birthDate) {
21 alert("잘못된 주민등록번호입니다.");
22 return;
23 }
24
25
26 buf = new Array(13);
27 for(i = 0; i < 6; i++)
28 buf[i] = parseInt(resno.charAt(i));
29 for(i = 6; i < 13; i++)
30 buf[i] = parseInt(resno.charAt(i+1));
31
32 multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
33 for(i=0, sum=0; i<12; i++)
34 sum += (buf[i] *= multipliers[i]);
35
36 if((11 - (sum % 11)) % 10 != buf[12]) {
37 alert("잘못된 주민등록번호입니다.");
38 return;
39 }
40
41 alert("정상적인 주민등록번호입니다.");
42 }