-
-
Save mertasan/d8961cc27cfe302b0cbfc1152e46a746 to your computer and use it in GitHub Desktop.
Validate TC ID
This file contains hidden or 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
| //======================================= | |
| // CHECK TC ID = | |
| //======================================= | |
| var checkTcNum = function(value) { | |
| value = value.toString(); | |
| var isEleven = /^[0-9]{11}$/.test(value); | |
| var totalX = 0; | |
| for (var i = 0; i < 10; i++) { | |
| totalX += Number(value.substr(i, 1)); | |
| } | |
| var isRuleX = totalX % 10 == value.substr(10,1); | |
| var totalY1 = 0; | |
| var totalY2 = 0; | |
| for (var i = 0; i < 10; i+=2) { | |
| totalY1 += Number(value.substr(i, 1)); | |
| } | |
| for (var i = 1; i < 10; i+=2) { | |
| totalY2 += Number(value.substr(i, 1)); | |
| } | |
| var isRuleY = ((totalY1 * 7) - totalY2) % 10 == value.substr(9,0); | |
| return isEleven && isRuleX && isRuleY; | |
| }; | |
| window.checkTcNum = checkTcNum; | |
| //-------- End of check tc id ---------// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment