Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 주민번호 체크 함수
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
You can’t perform that action at this time.