fixed bugs

This commit is contained in:
AmirHossein Mahmoodi
2025-02-25 14:59:01 +03:30
parent 46d5e7d2fe
commit 1d9d153657
25 changed files with 212 additions and 123 deletions

View File

@@ -0,0 +1,20 @@
function validateNationalCode(code) {
const invalidCodes = ["1111111111", "2222222222", "3333333333", "4444444444", "5555555555", "6666666666", "7777777777", "8888888888", "9999999999"];
if (invalidCodes.includes(code)) return false;
const L = code.length;
if (L < 8 || parseInt(code, 10) === 0) return false;
code = code.padStart(10, '0');
if (parseInt(code.substr(3, 6), 10) === 0) return false;
const c = parseInt(code.charAt(9), 10);
let s = 0;
for (let i = 0; i < 9; i++) {
s += parseInt(code.charAt(i), 10) * (10 - i);
}
s = s % 11;
return (s < 2 && c === s) || (s >= 2 && c === (11 - s));
}
export default validateNationalCode;