Created
November 29, 2020 15:53
-
-
Save avisiboni/d93c28a03fbf986d944ecdee323af725 to your computer and use it in GitHub Desktop.
Israel id number validation
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 validation(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