Validate a SIRET: check its length (14), its final code, and pass it
    through the Luhn algorithm.
1005
def siret_validator():
    """"""

    def _validate_siret(form, field, siret=""):
        """SIRET validator.

        A WTForm validator wants a form and a field as parameters. We
        also want to give directly a siret, for a scripting use.
        """
        if field is not None:
            siret = (field.data or "").strip()

        if len(siret) != 14:
            msg = _("SIRET must have exactly 14 characters ({count})").format(
                count=len(siret)
            )
            raise validators.ValidationError(msg)

        if not all(("0" <= c <= "9") for c in siret):
            if not siret[-3:] in SIRET_CODES:
                msg = _(
                    "SIRET looks like special SIRET but geographical "
                    "code seems invalid (%(code)s)",
                    code=siret[-3:],
                )
                raise validators.ValidationError(msg)

        elif not luhn(siret):
            msg = _("SIRET number is invalid (length is ok: verify numbers)")
            raise validators.ValidationError(msg)

    return _validate_siret
1189510
private void check(int length) {
    if (size + length >= buf.length) {
      buf = Arrays.copyOf(buf, buf.length + length + 16);
    }
  }
204439
public boolean validate() {

        if (m_end >= m_length) {
            m_end = m_length - 1;
        }

        return ((m_start >= 0) && (m_end >= 0) && (m_start <= m_end) && (m_length > 0));
    }
661029
def _validate_minlength(self, min_length, field, value):
        
        if isinstance(value, Iterable) and len(value) < min_length:
            self._error(field, errors.MIN_LENGTH, len(value))
1147379
def validate(self, val):
        
        if not isinstance(val, six.string_types):
            raise ValidationError("'%s' expected to be a string, got %s"
                                  % (val, generic_type_name(val)))
        if not six.PY3 and isinstance(val, str):
            try:
                val = val.decode('utf-8')
            except UnicodeDecodeError:
                raise ValidationError("'%s' was not valid utf-8")

        if self.max_length is not None and len(val) > self.max_length:
            raise ValidationError("'%s' must be at most %d characters, got %d"
                                  % (val, self.max_length, len(val)))
        if self.min_length is not None and len(val) < self.min_length:
            raise ValidationError("'%s' must be at least %d characters, got %d"
                                  % (val, self.min_length, len(val)))

        if self.pattern and not self.pattern_re.match(val):
            raise ValidationError("'%s' did not match pattern '%s'"
                                  % (val, self.pattern))
        return val
526169
protected function checkCorrectLength() {
        // If we have 13 chars, just flush the last one without throwing anything
        $c = strlen($this->text);
        if ($c === 13) {
            $this->text = substr($this->text, 0, 12);
        } elseif ($c !== 12) {
            throw new CINParseException('ean13', 'Must contain 12 digits, the 13th digit is automatically added.');
        }
    }
429922
def fit_size(min_length: int = 0, max_length: int = None,
             message=None) -> Filter_T:
    

    def validate(value):
        length = len(value) if value is not None else 0
        if length < min_length or \
                (max_length is not None and length > max_length):
            _raise_failure(message)
        return value

    return validate
1265250
private void validateCoefficients() {
        if (coefsValid)
            return;

        if (n >= 2) {
            double xBar = (double) sumX / n;
            double yBar = (double) sumY / n;

            a1 = (double) ((n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX));
            a0 = (double) (yBar - a1 * xBar);
        } else {
            a0 = a1 = Double.NaN;
        }

        coefsValid = true;
    }
833074
public static String validate(String code) {
        String plz = normalize(code);
        if (hasLandeskennung(plz)) {
            validateNumberOf(plz);
        } else {
            plz = LengthValidator.validate(plz, 3, 10);
        }
        return plz;
    }
976333
def validate(self):
        """"""
        # Literals representing boolean values or None are correctly representable and supported.
        if self.value is None or self.value is True or self.value is False:
            return

        # Literal safe strings are correctly representable and supported.
        if isinstance(self.value, six.string_types):
            validate_safe_string(self.value)
            return

        # Literal ints are correctly representable and supported.
        if isinstance(self.value, int):
            return

        # Literal empty lists, and non-empty lists of safe strings, are
        # correctly representable and supported.
        if isinstance(self.value, list):
            if len(self.value) > 0:
                for x in self.value:
                    validate_safe_string(x)
            return

        raise GraphQLCompilationError(u'Cannot represent literal: {}'.format(self.value))
993800
public static int checkBetween(int value, int min, int max) {
		if (value < min || value > max) {
			throw new IllegalArgumentException(StrUtil.format("Length must be between {} and {}.", min, max));
		}
		return value;
	}
881948
function computeCombinationLength(elementNumber, combinationLength) {
    elementNumber = Number(elementNumber);
    combinationLength = Number(combinationLength);
    if (!_regex.regex.positiveInteger.test(String(elementNumber))) {
        throw new Error("elementNumber should be positiveNumber but got " + elementNumber);
    }
    if (!(_regex.regex.positiveInteger.test(String(combinationLength)) || combinationLength === 0)) {
        throw new Error("elementNumber should be positiveNumber or 0 but got " + combinationLength);
    }
    if (combinationLength > elementNumber) {
        throw new Error("The max value of combinationLength should be " + elementNumber + " but got " + combinationLength);
    }
    if (combinationLength === 0) {
        return 1;
    }
    return computeFactorial(elementNumber) / (computeFactorial(combinationLength) * computeFactorial(elementNumber - combinationLength));
}
712288
private int determineSize(List<Match> t) {
        Match firstMatch = t.get(0);
        if (!(firstMatch.token instanceof SimpleToken)) {
            return t.size();
        }
        int charLength = 0;
        for (Match m : t) {
            SimpleToken token = (SimpleToken) m.token;
            charLength += token.getNormalized().length();
        }
        return charLength;
    }
1147404
private static void checkViolations(List<String> givenViolations,
			List<String> expectedValidationViolations) {

		/*
		 * check if number of expected violations matches the given violations
		 */
		Assert.assertEquals(
				String.format(
						"number of expected validation violations (%s) does not match the number of given violations (%s)",
						StringUtils.join(expectedValidationViolations,
								LIST_DELIMITER), StringUtils.join(
								givenViolations, LIST_DELIMITER)),
				expectedValidationViolations.size(), givenViolations.size());

		/*
		 * check if the set of given violations matches the expected violations
		 */
		boolean listsAreCongruent = true;

		List<String> givenButNotExpected = new ArrayList<String>();

		for (String givenViolation : givenViolations) {

			if (!expectedValidationViolations.contains(givenViolation)) {
				listsAreCongruent = false;
				givenButNotExpected.add(givenViolation);
			}
		}

		Assert.assertTrue(
				String.format(
						"the violations (%s) where given but not expected: all given violations (%s), all expected violations (%s)",
						StringUtils.join(givenButNotExpected, LIST_DELIMITER),
						StringUtils.join(givenViolations, LIST_DELIMITER),
						StringUtils.join(expectedValidationViolations,
								LIST_DELIMITER)), listsAreCongruent);
	}
440604
def validate_clabe(clabe: str) -> bool:
    
    return (clabe.isdigit() and
            len(clabe) == CLABE_LENGTH and
            clabe[:3] in BANKS.keys() and
            clabe[-1] == compute_control_digit(clabe))
57730
@Override
	protected void validateComponent(final List<Diagnostic> diags) {
		super.validateComponent(diags);

		if (!isEmpty()) {
			String value = getValueAsString();

			// Minimum Length
			int min = getMinLength();

			if (min > 0 && value.length() < min) {
				diags.add(
						createErrorDiagnostic(InternalMessages.DEFAULT_VALIDATION_ERROR_MIN_LENGTH,
								this,
								String.valueOf(min)));
			}

			// Maximum Length
			int max = getMaxLength();

			if (max > 0 && value.length() > max) {
				diags.add(
						createErrorDiagnostic(InternalMessages.DEFAULT_VALIDATION_ERROR_MAX_LENGTH,
								this,
								String.valueOf(max)));
			}
		}
	}
928495
@Override
	protected void validateComponent(final List<Diagnostic> diags) {
		super.validateComponent(diags);

		if (!isEmpty()) {
			String value = getValueAsString();

			// Maximum Length
			int max = getMaxLength();

			if (max > 0 && value.length() > max) {
				diags.add(
						createErrorDiagnostic(InternalMessages.DEFAULT_VALIDATION_ERROR_MAX_LENGTH,
								this,
								String.valueOf(max)));
			}

			// Minimum Length
			int min = getMinLength();

			if (min > 0 && value.length() < min) {
				diags.add(
						createErrorDiagnostic(InternalMessages.DEFAULT_VALIDATION_ERROR_MIN_LENGTH,
								this,
								String.valueOf(min)));
			}

			// Pattern
			Pattern pattern = getComponentModel().pattern;
			if (pattern != null) {
				Matcher matcher = pattern.matcher(value);
				if (!matcher.matches()) {
					diags.add(createErrorDiagnostic(
							InternalMessages.DEFAULT_VALIDATION_ERROR_INVALID_PATTERN, this));
				}
			}
		}
	}