Last active
September 12, 2018 01:28
-
-
Save susemeee/ccf35b90806bc29ee465420696cd2e26 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
// 법인번호 오류검증 공식 | |
// 법인번호에서 마지막 자리를 제외한 | |
// 앞에 모든 자리수를 1과 2를 순차적으로 곱한다. | |
// 예) 1234567890123 | |
// ************ | |
// 121212121212 | |
// 각각 곱한 수를 모든 더하고 10으로 나눈 나머지 수를 구한다. | |
// (각각더한수 % 10) | |
// 나눈 나머지 수와 법인번호 마지막 번호가 일치하면 검증일치 | |
function isValidCorporationId(value = '') { | |
const rawValue = value.replace(/[^\d]/g, '').split('').map(r => Number(r)); | |
const checksum = rawValue.pop(); | |
const sum = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] | |
.map((n, i) => n * rawValue[i]).reduce((sum, n) => { | |
sum += n; | |
return sum; | |
}, 0) % 10; | |
return sum === (10 - checksum) % 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment