Validate if the field has a `max_digits` and `decimal_places`
        And generating the unique decimal number.
491854
def randomDecimalField(self, model_class, field_name):
        
        decimal_field = model_class._meta.get_field(field_name)
        max_digits = None
        decimal_places = None

        if decimal_field.max_digits is not None:
            max_digits = decimal_field.max_digits
        if decimal_field.decimal_places is not None:
            decimal_places = decimal_field.decimal_places

        digits = random.choice(range(100))
        if max_digits is not None:
            start = 0
            if max_digits < start:
                start = max_digits - max_digits
            digits = int(
                "".join([
                    str(x) for x in random.sample(
                        range(start, max_digits),
                        max_digits - 1
                    )
                ])
            )
        places = random.choice(range(10, 99))
        if decimal_places is not None:
            places = str(
                random.choice(range(9999 * 99999))
            )[:decimal_places]

        return float(
            str(digits)[:decimal_places] + "." + str(places)
        )
972873
def _validate(self, value):
        
        if value is not None:
            raise ValueError('The pk for %s is "auto-increment", you must not fill it' %
                            self._model.__name__)
        key = self._instance.make_key(self._model._name, 'max_pk')
        return self.normalize(self.connection.incr(key))
1118487
def input_validate_int(value, name, max_value=None):
    
    if type(value) is not int:
        raise pyhsm.exception.YHSM_WrongInputType(name, int, type(value))
    if max_value != None and value > max_value:
        raise pyhsm.exception.YHSM_WrongInputSize(name, max_value, value)
    return value
783957
def _validate_number(self, input_number, path_to_root, object_title=''):

        '''
            
        '''

        rules_path_to_root = re.sub('\[\d+\]', '[0]', path_to_root)
        input_criteria = self.keyMap[rules_path_to_root]
        error_dict = {
            'object_title': object_title,
            'model_schema': self.schema,
            'input_criteria': input_criteria,
            'failed_test': 'value_datatype',
            'input_path': path_to_root,
            'error_value': input_number,
            'error_code': 4001
        }
        if 'integer_data' in input_criteria.keys():
            if input_criteria['integer_data'] and not isinstance(input_number, int):
                error_dict['failed_test'] = 'integer_data'
                error_dict['error_code'] = 4021
                raise InputValidationError(error_dict)
        if 'min_value' in input_criteria.keys():
            if input_number < input_criteria['min_value']:
                error_dict['failed_test'] = 'min_value'
                error_dict['error_code'] = 4022
                raise InputValidationError(error_dict)
        if 'max_value' in input_criteria.keys():
            if input_number > input_criteria['max_value']:
                error_dict['failed_test'] = 'max_value'
                error_dict['error_code'] = 4023
                raise InputValidationError(error_dict)
        if 'greater_than' in input_criteria.keys():
            if input_number <= input_criteria['greater_than']:
                error_dict['failed_test'] = 'greater_than'
                error_dict['error_code'] = 4024
                raise InputValidationError(error_dict)
        if 'less_than' in input_criteria.keys():
            if input_number >= input_criteria['less_than']:
                error_dict['failed_test'] = 'less_than'
                error_dict['error_code'] = 4025
                raise InputValidationError(error_dict)
        if 'equal_to' in input_criteria.keys():
            if input_number != input_criteria['equal_to']:
                error_dict['failed_test'] = 'equal_to'
                error_dict['error_code'] = 4026
                raise InputValidationError(error_dict)
        if 'discrete_values' in input_criteria.keys():
            if input_number not in input_criteria['discrete_values']:
                error_dict['failed_test'] = 'discrete_values'
                error_dict['error_code'] = 4041
                raise InputValidationError(error_dict)
        if 'excluded_values' in input_criteria.keys():
            if input_number in input_criteria['excluded_values']:
                error_dict['failed_test'] = 'excluded_values'
                error_dict['error_code'] = 4042
                raise InputValidationError(error_dict)

    # TODO: validate number against identical to reference

    # TODO: run lambda function and call validation url

        return input_number
1009372
protected void validateField(int field) {
        int y;
        switch (field) {
        case DAY_OF_MONTH:
            y = handleGetExtendedYear();
            validateField(field, 1, handleGetMonthLength(y, internalGet(MONTH)));
            break;
        case DAY_OF_YEAR:
            y = handleGetExtendedYear();
            validateField(field, 1, handleGetYearLength(y));
            break;
        case DAY_OF_WEEK_IN_MONTH:
            if (internalGet(field) == 0) {
                throw new IllegalArgumentException("DAY_OF_WEEK_IN_MONTH cannot be zero");
            }
            validateField(field, getMinimum(field), getMaximum(field));
            break;
        default:
            validateField(field, getMinimum(field), getMaximum(field));
            break;
        }
    }
595778
def validate_fixed(datum, schema, **kwargs):
    
    return (
            (isinstance(datum, bytes) and len(datum) == schema['size'])
            or (isinstance(datum, decimal.Decimal))
    )
635953
def _generate_validator(self, field):
        """"""
        validator = self._determine_validator_type(field.data_type,
                                                   fmt_var(field.name),
                                                   field.has_default)
        value = fmt_var(
            field.name) if not field.has_default else '{} ?: {}'.format(
                fmt_var(field.name), fmt_default_value(field))
        if validator:
            self.emit('{}({});'.format(validator, value))
462508
def roundup(ctx, number, num_digits):
    
    number = conversions.to_decimal(number, ctx)
    num_digits = conversions.to_integer(num_digits, ctx)

    return decimal_round(number, num_digits, ROUND_UP)
834124
def validate_multiple_of(value, divisor, **kwargs):
    
    if not decimal.Decimal(str(value)) % decimal.Decimal(str(divisor)) == 0:
        raise ValidationError(
            MESSAGES['multiple_of']['invalid'].format(divisor, value),
        )
446562
protected function validateDecimalsCurrency()
    {
        $field = 'decimals';
        $value = $this->getSubmitted($field);

        if (!isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        if (preg_match('/^[0-2]+$/', $value) !== 1) {
            $this->setErrorInvalid($field, $this->translation->text('Decimals'));
            return false;
        }

        return true;
    }
140145
protected function _validator_max($input, $value, $max) {
		if (!is_string($value) && !is_integer($value) && !is_float($value)) return false;
		if (is_string($value)) $value = (int)$value;
		return $value <= $max;
	}
1282586
def validate_unique(self):
        
        form_errors = []
        try:
            super(LocalisedForm, self).validate_unique()
        except ValidationError as e:
            form_errors += e.messages

        # add unique validation for the localized fields.
        localized_fields_checks = self._get_localized_field_checks()
        bad_fields = set()

        field_errors, global_errors = self._perform_unique_localized_field_checks(localized_fields_checks)
        bad_fields.union(field_errors)
        form_errors.extend(global_errors)
        
        for field_name in bad_fields:
            del self.cleaned_data[field_name]
        if form_errors:
            # Raise the unique together errors since they are considered
            # form-wide.
            raise ValidationError(form_errors)
1289068
def format_currency_field(__, prec, number, locale):
    """"""
    locale = Locale.parse(locale)
    currency = get_territory_currencies(locale.territory)[0]
    if prec is None:
        pattern, currency_digits = None, True
    else:
        prec = int(prec)
        pattern = locale.currency_formats['standard']
        pattern = modify_number_pattern(pattern, frac_prec=(prec, prec))
        currency_digits = False
    return format_currency(number, currency, pattern, locale=locale,
                           currency_digits=currency_digits)
854559
def format_percent_field(__, prec, number, locale):
    """"""
    prec = PERCENT_DECIMAL_DIGITS if prec is None else int(prec)
    locale = Locale.parse(locale)
    pattern = locale.percent_formats.get(None)
    return pattern.apply(number, locale, force_frac=(prec, prec))
740220
def valid_max_age(number):
    ""
    if isinstance(number, basestring):
        try:
            number = long(number)
        except (ValueError, TypeError):
            return False
    if number >= 0 and number % 1 == 0:
        return True
    return False
1139218
def filter_decimal(string, default=None, lower=None, upper=None):
    """"""
    try:
        d = decimal.Decimal(string)
        if lower is not None and d < lower:
            raise InvalidInputError("value too small")
        if upper is not None and d >= upper:
            raise InvalidInputError("value too large")
        return d
    except decimal.InvalidOperation:
        if not string and default is not None:
            # empty string, default was given
            return default
        else:
            raise InvalidInputError("invalid decimal number")
1255117
function intValidatorWithErrors( n, min, max, caller, name ) {
            if ( n < min || n > max || n != truncate(n) ) {
                raise( caller, ( name || 'decimal places' ) +
                  ( n < min || n > max ? ' out of range' : ' not an integer' ), n );
            }

            return true;
        }