Skip to content

Instantly share code, notes, and snippets.

@NicmeisteR
Created November 2, 2020 12:37
Show Gist options
  • Save NicmeisteR/5377201bf7ebd70a9e1410d93c31d601 to your computer and use it in GitHub Desktop.
Save NicmeisteR/5377201bf7ebd70a9e1410d93c31d601 to your computer and use it in GitHub Desktop.
AngularJS Tax Validator (South Africa)
this.validTax = false;
this.taxValidator = function (taxnumber) {
taxnumber = taxnumber.split("");
var taxMultiplied = 0;
for (let index = 0; index < taxnumber.length; index++) {
if ((index % 2) == 1) {
taxMultiplied += taxnumber[index] * 1;
}
else {
if ((taxnumber[index] * 2) > 9) {
var num = (taxnumber[index] * 2).toString().split("");
taxMultiplied += (num[0] * 1) + (num[1] * 1);
}
else {
taxMultiplied += taxnumber[index] * 2;
}
}
}
if (taxMultiplied.toString().split("")[1] === "0") {
this.validTax = true;
}
else {
this.validTax = false;
}
}
this.taxValidator("0000000000");
console.log(this.validTax);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment