Checks a candidate number for validity according to the Luhn
    algorithm (used in validation of, for example, credit cards).
    Both numeric and string candidates are accepted.
496151
def luhn(candidate):
    
    if not isinstance(candidate, six.string_types):
        candidate = str(candidate)
    try:
        evens = sum(int(c) for c in candidate[-1::-2])
        odds = sum(LUHN_ODD_LOOKUP[int(c)] for c in candidate[-2::-2])
        return ((evens + odds) % 10 == 0)
    except ValueError:  # Raised if an int conversion fails
        return False
500159
def validate(self, tracking_number):
        ""
        tracking_num = tracking_number[2:-1]
        odd_total = 0
        even_total = 0

        for ii, digit in enumerate(tracking_num.upper()):
            try:
                value = int(digit)
            except ValueError:
                value = int((ord(digit) - 63) % 10)
            if (ii + 1) % 2:
                odd_total += value
            else:
                even_total += value

        total = odd_total + even_total * 2
        check = ((total - (total % 10) + 10) - total) % 10
        return (check == int(tracking_number[-1:]))
396346
private boolean checkEeTin(final String ptin) {
    final int checkSum = ptin.charAt(10) - '0';
    int calculatedCheckSum = ((ptin.charAt(0) - '0') * 1 //
        + (ptin.charAt(1) - '0') * 2 //
        + (ptin.charAt(2) - '0') * 3 //
        + (ptin.charAt(3) - '0') * 4 //
        + (ptin.charAt(4) - '0') * 5 //
        + (ptin.charAt(5) - '0') * 6 //
        + (ptin.charAt(6) - '0') * 7 //
        + (ptin.charAt(7) - '0') * 8 //
        + (ptin.charAt(8) - '0') * 9 //
        + (ptin.charAt(9) - '0') * 1) //
        % MODULO_11;
    if (calculatedCheckSum == 10) {
      calculatedCheckSum = ((ptin.charAt(0) - '0') * 3 //
          + (ptin.charAt(1) - '0') * 4 //
          + (ptin.charAt(2) - '0') * 5 //
          + (ptin.charAt(3) - '0') * 6 //
          + (ptin.charAt(4) - '0') * 7 //
          + (ptin.charAt(5) - '0') * 8 //
          + (ptin.charAt(6) - '0') * 9 //
          + (ptin.charAt(7) - '0') * 1 //
          + (ptin.charAt(8) - '0') * 2 //
          + (ptin.charAt(9) - '0') * 3) //
          % MODULO_11 % 10;
    }
    return checkSum == calculatedCheckSum;
  }
1260697
public static function isValid(string $number) : bool
    {
        if (ctype_digit($number)) {
            return self::checksum($number) === 0;
        }

        return false;
    }
1215246
@Override
    public void validate() {
        if (value == null) {
            throw new NoValueGivenException(getPath());
        }

        if (valids.size() != 0) {
            boolean ok = false;
            String valString = (value != null) ? value.toString() : "";

            for (int i = 0; i < valids.size(); i++) {
                if (valids.get(i).equals(valString)) {
                    ok = true;
                    break;
                }
            }

            if (!ok) {
                throw new NoValidValueException(getPath(), valString);
            }
        }

        setValid(true);
    }
475422
private boolean checkAtTaxNumber(final String ptaxNumber) {
    final int checkSum = ptaxNumber.charAt(8) - '0';
    final int sum = ptaxNumber.charAt(0) - '0' + squareSum((ptaxNumber.charAt(1) - '0') * 2) //
        + ptaxNumber.charAt(2) - '0' + squareSum((ptaxNumber.charAt(3) - '0') * 2) //
        + ptaxNumber.charAt(4) - '0' + squareSum((ptaxNumber.charAt(5) - '0') * 2) //
        + ptaxNumber.charAt(6) - '0' + squareSum((ptaxNumber.charAt(7) - '0') * 2);
    final int calculatedCheckSum = (80 - sum) % 10;
    return checkSum == calculatedCheckSum;
  }
388781
function toNumberOrUndefined(n) {
    if (n === null || n === undefined) { return undefined; }
    if (validation.isObject(n) || validation.isArray(n)) { return undefined; }
    if (typeof n === 'boolean' || (typeof n === 'string' && n.length < 1)) { return undefined; }
    return isNaN(+n) ? undefined : +n;
}
269849
def check_validity(self):
        """""""
        # pianoroll
        if not isinstance(self.pianoroll, np.ndarray):
            raise TypeError("`pianoroll` must be a numpy array.")
        if not (np.issubdtype(self.pianoroll.dtype, np.bool_)
                or np.issubdtype(self.pianoroll.dtype, np.number)):
            raise TypeError("The data type of `pianoroll` must be np.bool_ or "
                            "a subdtype of np.number.")
        if self.pianoroll.ndim != 2:
            raise ValueError("`pianoroll` must have exactly two dimensions.")
        if self.pianoroll.shape[1] != 128:
            raise ValueError("The length of the second axis of `pianoroll` "
                             "must be 128.")
        # program
        if not isinstance(self.program, int):
            raise TypeError("`program` must be int.")
        if self.program < 0 or self.program > 127:
            raise ValueError("`program` must be in between 0 to 127.")
        # is_drum
        if not isinstance(self.is_drum, bool):
            raise TypeError("`is_drum` must be bool.")
        # name
        if not isinstance(self.name, string_types):
            raise TypeError("`name` must be a string.")
91145
def luhn_calc(number, chars=DIGITS):
    '''
    

    '''

    checksum = luhn_checksum(str(number) + chars[0], chars)
    return chars[-checksum]
919979
private void verifyNumber(Number value, Number minimum, Number maximum) {

    if (minimum != null) {
      if (maximum != null) {
        assert ((value.doubleValue() >= minimum.doubleValue()) || (value.doubleValue() <= maximum.doubleValue()));
      } else {
        assert (value.doubleValue() >= minimum.doubleValue());
      }
    } else if (maximum != null) {
      assert (value.doubleValue() <= maximum.doubleValue());
    } else {
      throw new NlsNullPointerException("minimum & maximum");
    }
  }
726902
def valid(self, cnpj):
        
        if len(cnpj) != 14:
            return False

        tam = 12
        nums = cnpj[:tam]
        digs = cnpj[tam:]

        tot = 0
        pos = tam-7
        for i in range(tam, 0, -1):
            tot = tot + int(nums[tam-i])*pos
            pos = pos - 1
            if pos < 2:
                pos = 9
        res = 0 if tot % 11 < 2 else 11 - (tot % 11)
        if res != int(digs[0]):
            return False

        tam = tam + 1
        nums = cnpj[:tam]
        tot = 0
        pos = tam-7
        for i in range(tam, 0, -1):
            tot = tot + int(nums[tam-i])*pos
            pos = pos - 1
            if pos < 2:
                pos = 9
        res = 0 if tot % 11 < 2 else 11 - (tot % 11)
        if res != int(digs[1]):
            return False

        return True
242568
public static void validate(BigInteger nummer, Ort ort) {
        if (nummer.compareTo(BigInteger.ONE) < 0) {
            throw new InvalidValueException(nummer, "number");
        }
        validate(ort);
    }
959211
def check_candidate(a, d, n, s):
    """"""
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2 ** i * d, n) == n - 1:
            return False
    return True
371875
public static boolean isValid(String fodselsnummer) {
		try {
			FodselsnummerValidator.getFodselsnummer(fodselsnummer);
			return true;
		} catch (IllegalArgumentException e) {
			return false;
		}
	}
268084
private boolean checkChecksumISBN10(final String isbn) {
    int sum = 0;
    for (int i = 0; i < isbn.length() - 1; i++) {
      sum += (isbn.charAt(i) - '0') * (i + 1);
    }
    final char checkSum = isbn.charAt(9);
    return sum % 11 == (checkSum == 'X' ? 10 : checkSum - '0');
  }
947232
public function rule_credit_card($a)
    {
        // Card formats keep changing and there is too high a risk
        // of false negatives if we get clever. So we just check it
        // with the Luhn Mod 10 formula

        // Calculate the Luhn check number

        $msg = 'Not a valid card number';

        $sum = 0;
        $alt = false;

        for ($i = strlen($a) - 1; $i >= 0; --$i) {
            $n = substr($a, $i, 1);
            if ($alt) {
                //square n
                $n *= 2;
                if ($n > 9) {
                    //calculate remainder
                    $n = ($n % 10) + 1;
                }
            }
            $sum += $n;
            $alt = !$alt;
        }

        // If $sum divides exactly by 10 it's valid

        if (!($sum % 10 == 0)) {
            return $this->fail($msg);
        } else {
            // Luhn check seems to return true for any string of 0s

            $stripped = str_replace('0', '', $a);

            if (strlen($stripped) == 0) {
                return $this->fail($msg);
            }
        }
    }
32045
function isCreditCard(str) {
  (0, _assertString.default)(str);
  var sanitized = str.replace(/[- ]+/g, '');

  if (!creditCard.test(sanitized)) {
    return false;
  }

  var sum = 0;
  var digit;
  var tmpNum;
  var shouldDouble;

  for (var i = sanitized.length - 1; i >= 0; i--) {
    digit = sanitized.substring(i, i + 1);
    tmpNum = parseInt(digit, 10);

    if (shouldDouble) {
      tmpNum *= 2;

      if (tmpNum >= 10) {
        sum += tmpNum % 10 + 1;
      } else {
        sum += tmpNum;
      }
    } else {
      sum += tmpNum;
    }

    shouldDouble = !shouldDouble;
  }

  return !!(sum % 10 === 0 ? sanitized : false);
}