Created
November 2, 2020 12:37
-
-
Save NicmeisteR/5377201bf7ebd70a9e1410d93c31d601 to your computer and use it in GitHub Desktop.
AngularJS Tax Validator (South Africa)
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
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