Created
October 19, 2017 02:51
-
-
Save gracefullight/332eb8102bca4b8ab840ec47f6a6d3d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 주민번호 체크 함수 | |
function checkPersonalNumber(jumin) { | |
jumin = String(jumin); | |
if(jumin.length !== 13) { | |
return false; | |
} | |
var sum = 0; | |
var j = 2; | |
var checker = Number(jumin.charAt(12)); | |
var month = jumin.substr(2, 2); | |
var day = jumin.substr(4, 2); | |
/** | |
* 1900년대 1 2, | |
* 2000년대 3 4, | |
* 1900년대 외국인 5 6, | |
* 2000년대 외국인 7 8 | |
*/ | |
var sex = jumin.charAt(6); | |
for(var i = 0; i < 12; i++) { | |
if(i === 8) { | |
j = 2; | |
} | |
sum += jumin.charAt(i) * j; | |
j += 1; | |
} | |
var checker2 = (11 - (sum % 11)) % 10; | |
if((checker !== checker2 && checker !== ((checker2 + 2) % 10)) | |
|| month > 12 | |
|| day > 31 | |
|| !/[1-8]/.test(sex) | |
) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment