Skip to content

Instantly share code, notes, and snippets.

@OpenGrid
Created August 3, 2012 21:54
Show Gist options
  • Select an option

  • Save OpenGrid/3251884 to your computer and use it in GitHub Desktop.

Select an option

Save OpenGrid/3251884 to your computer and use it in GitHub Desktop.

Revisions

  1. OpenGrid revised this gist Aug 3, 2012. 1 changed file with 12 additions and 13 deletions.
    25 changes: 12 additions & 13 deletions isNIPvalid.js
    Original file line number Diff line number Diff line change
    @@ -2,17 +2,16 @@
    Check for validity of polish VAT ID number: NIP
    */

    function isNIPvalid(NIP) {
    var controlSum = 0, factors = [6, 5, 7, 2, 3, 4, 5, 6, 7];
    NIP += '';
    NIP = NIP.replace(/[^0-9]+/g,'');
    if(NIP.length < 10 || NIP.length > 10)
    return false;
    for(var c = 0; c <= 8; c++) {
    controlSum += parseInt(NIP.charAt(c)) * factors[c];
    }
    if(controlSum % 11 == parseInt(NIP.charAt(9))) {
    return true;
    }
    return false;
    function NIPIsValid(nip) {
    var weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
    nip = nip.replace(/[\s-]/g, '');

    if (nip.length == 10 && parseInt(nip, 10) > 0) {
    var sum = 0;
    for(var i = 0; i < 9; i++){
    sum += nip[i] * weights[i];
    }
    return (sum % 11) == nip[9];
    }
    return false;
    }
  2. OpenGrid revised this gist Aug 3, 2012. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions isNIPvalid.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,17 @@
    function isNIPvalid(nip) {
    /*
    Check for validity of polish VAT ID number: NIP
    */

    function isNIPvalid(NIP) {
    var controlSum = 0, factors = [6, 5, 7, 2, 3, 4, 5, 6, 7];
    nip += '';
    nip = nip.replace(/[^0-9]+/g,'');
    if(nip.length < 10 || nip.length > 10)
    NIP += '';
    NIP = NIP.replace(/[^0-9]+/g,'');
    if(NIP.length < 10 || NIP.length > 10)
    return false;
    for(var c = 0; c <= 8; c++) {
    controlSum += parseInt(nip.charAt(c)) * factors[c];
    controlSum += parseInt(NIP.charAt(c)) * factors[c];
    }
    if(controlSum % 11 == parseInt(nip.charAt(9))) {
    if(controlSum % 11 == parseInt(NIP.charAt(9))) {
    return true;
    }
    return false;
  3. OpenGrid created this gist Aug 3, 2012.
    14 changes: 14 additions & 0 deletions isNIPvalid.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    function isNIPvalid(nip) {
    var controlSum = 0, factors = [6, 5, 7, 2, 3, 4, 5, 6, 7];
    nip += '';
    nip = nip.replace(/[^0-9]+/g,'');
    if(nip.length < 10 || nip.length > 10)
    return false;
    for(var c = 0; c <= 8; c++) {
    controlSum += parseInt(nip.charAt(c)) * factors[c];
    }
    if(controlSum % 11 == parseInt(nip.charAt(9))) {
    return true;
    }
    return false;
    }