Last active
March 8, 2023 21:08
-
-
Save tomerof/f595fed7da0b0e40e031f69883948983 to your computer and use it in GitHub Desktop.
validate israeli ID number
This file contains hidden or 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 isIsraeliId(id) { | |
id = String(id).trim(); | |
if (id.length > 9 || isNaN(id)) return false; | |
id = id.length < 9 ? ("00000000" + id).slice(-9) : id; | |
return Array.from(id, Number).reduce((counter, digit, i) => { | |
const step = digit * ((i % 2) + 1); | |
return counter + (step > 9 ? step - 9 : step); | |
}) % 10 === 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment