Skip to content

Instantly share code, notes, and snippets.

@jonaszuberbuehler
Last active October 11, 2021 15:44
Show Gist options
  • Save jonaszuberbuehler/c6f37fc3eff44a3f69b8115e6593cf64 to your computer and use it in GitHub Desktop.
Save jonaszuberbuehler/c6f37fc3eff44a3f69b8115e6593cf64 to your computer and use it in GitHub Desktop.
function isValidateSVNumber(toValidate) {
const number = toValidate.replaceAll('.', '');
if (number.length < 13) {
return false;
}
const parts = number.split('');
const checksum = parseInt(parts[parts.length - 1]);
const sum = parts.reverse().slice(1).reduce((sum, number, index) => {
if (index % 2 === 0) {
return sum + parseInt(number) * 3;
}
return sum + parseInt(number);
}, 0);
return (sum + checksum) % 10 === 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment