Skip to content

Instantly share code, notes, and snippets.

@Eomerx
Last active October 13, 2022 17:47
Show Gist options
  • Save Eomerx/9ee93dd6ea4d77cb2ac3 to your computer and use it in GitHub Desktop.
Save Eomerx/9ee93dd6ea4d77cb2ac3 to your computer and use it in GitHub Desktop.

Revisions

  1. Ömer Aslanbakan renamed this gist Feb 26, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Ömer Aslanbakan created this gist Feb 26, 2015.
    24 changes: 24 additions & 0 deletions validate-tc-id
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    //=======================================
    // 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 ---------//