Skip to content

Instantly share code, notes, and snippets.

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