Validates a number
439622
def validate(number)
      criterii = {}
      criterii[:luhn] = Check.luhn number
      criterii[:type] = !!infos(number)

      valid = criterii.all? { |_, v| v == true }

      {
        valid: valid,
        details: criterii
      }
    end
1132074
function toNumber(value) {
        var _this = this;

        if (validateHelpers.isArray(value)) {
            return value.map(function (a) {
                return _this.toNumber(a);
            });
        }

        var number = parseFloat(value);

        if (number === undefined) {
            return value;
        }

        if (number.toString().length !== value.toString().length && !validateHelpers.isNumeric(value)) {
            return value;
        }

        return validateHelpers.isNumber(number) ? value : number;
    }
831478
def validate(self, value, messages=None):
        
        valid     = True
        primitive = value

        def log(msg):
            if messages is not None:
                messages.append(msg)

        if self.enum:
            if value not in self.enum.keys():
                valid = False
                args  = (self.name, str(value))
                log("%s value '%s' not in allowed enumerated values." % args)
            else:
                primitive = int(self.enum[value])

        if self.type:
            if self.type.validate(primitive, messages, self.name) is False:
                valid = False

        if self.range:
            if primitive < self.range[0] or primitive > self.range[1]:
                valid = False
                args  = (self.name, str(primitive), self.range[0], self.range[1])
                log("%s value '%s' out of range [%d, %d]." % args)

        return valid
432847
def check_int(num,
              num_descr='number',
              min_value=0,
              max_value=np.Inf):
    """"""

    if not np.isfinite(num) or num < min_value or num > max_value:
        raise ValueError('{}={} is not finite or '
                         'is not >= {} or '
                         'is not < {}'.format(num_descr, num, min_value, max_value))

    return int(num)
1000318
function checkNum(nums, min, max){
  if(nums == null)
    return false;

  if(nums == -1)
    return true;

  for(let i = 0; i < nums.length; i++){
    if(nums[i]<min || nums[i]>max)
      return false;
  }

  return true;
}
683950
def check_errors
      if @value && @value.is_a?(Numeric)
        if @args.is_a?(Hash)

          @args.each do |arg, val|
            case arg
            when :min
              add_error("number must be greater than #{val}") if @value < val
            when :max
              add_error("number must be less than #{val}") if @value > val
            end
          end

        end
      else
        message = (@args.is_a?(Hash) && @args[:message]) || 'must be a number'
        add_error(message)
      end
    end
578286
function validateType(type, value) {
	var numberRegex;
	switch (type.toLowerCase()) {
		case 'integer':
		case 'int':
			numberRegex = new RegExp('^[-+]?[0-9]+$');
			if (numberRegex.test(value)) {
				return parseInt(value);
			}
			else {
				throw new InvalidInputError(value + " wasn't of type " + type);
			}
			break;
		case 'number':
		case 'float':
		case 'double':
			numberRegex = new RegExp('^[-+]?[0-9]*([\.,][0-9]+)?$');
			if (numberRegex.test(value)) {
				return parseFloat(value);
			}
			else {
				throw new InvalidInputError(value + " wasn't of type " + type);
			}
			break;
		case 'string':
			//Anything is a string
			return value;
		case 'path':
			// A path that may be relative or absolute. We should parse this into an absolute path
			if(path.isAbsolute(value)) {
				return path.normalize(value);
			}
			return path.resolve(process.cwd(), value);
		default:
			return value;
			break;
	}
}
1205385
def validate(self):
        
        super(NumericFilterBase, self).validate()

        self.not_null = False

        if self._value.startswith('+'):
            self._cmp = operator.gt
            self._rt_cmp = 'greater'
            self._value = self._value[1:]
        elif self._value.startswith('-'):
            self._cmp = operator.lt
            self._rt_cmp = 'less'
            self._value = self._value[1:]
        else:
            self._cmp = operator.eq
            self._rt_cmp = 'equal'
549578
def _validate_int(name, value, limits=(), strip='%'):
    '''
    
    '''
    comment = ''
    # Must be integral
    try:
        if isinstance(value, string_types):
            value = value.strip(' ' + strip)
        value = int(value)
    except (TypeError, ValueError):
        comment += '{0} must be an integer '.format(name)
    # Must be in range
    else:
        if len(limits) == 2:
            if value < limits[0] or value > limits[1]:
                comment += '{0} must be in the range [{1[0]}, {1[1]}] '.format(name, limits)
    return value, comment
234772
def validate(self, value):
        """"""
        value = self.pre_validate(value)
        if not self._typecheck(value):
            raise ValueError('%r failed type check' % value)
        return value
1146355
def luhn_validate(number):
    

    sum = 0
    parity = len(number) % 2
    for i, digit in enumerate([int(x) for x in number]):
        if i % 2 == parity:
            digit *= 2
            if digit > 9:
                digit -= 9
        sum += digit
    return sum % 10 == 0
269281
def value_validate(self, value):
        
        if not isinstance(value, six.integer_types):
            raise tldap.exceptions.ValidationError("should be a integer")

        try:
            return str(value)
        except (TypeError, ValueError):
            raise tldap.exceptions.ValidationError("is invalid integer")
181661
def number_check(*args, func=None):
    """"""
    func = func or inspect.stack()[2][3]
    for var in args:
        if not isinstance(var, numbers.Number):
            name = type(var).__name__
            raise DigitError(
                f'Function {func} expected number, {name} got instead.')
986687
def validate(self, instance, value):
        """"""
        try:
            intval = int(value)
            if not self.cast and abs(value - intval) > TOL:
                self.error(
                    instance=instance,
                    value=value,
                    extra='Not within tolerance range of {}.'.format(TOL),
                )
        except (TypeError, ValueError):
            self.error(instance, value, extra='Cannot cast to integer.')
        _in_bounds(self, instance, intval)
        return intval
1046505
private function validateAlnum(): bool
    {
        $charClass = '[:alnum:]';
        if ($this->options['allow-spaces'] === true) {
            $charClass .= '[:space:]';
        }
        if ($this->options['allow-whitespaces'] === true) {
            $charClass .= '[:blank:]';
        }
        $modifier = '';
        if ($this->options['utf-8'] === true) {
            $modifier = 'u';
        }

        $isValid = \preg_match('/^['.$charClass.']+$/'.$modifier, $this->value) ? true : false;
        if (!$isValid) {
            $this->setError(self::VALIDATOR_ERROR_ALNUM_NOT_VALID);

            if ($this->options['allow-whitespaces'] === true && $this->options['allow-spaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID);
            } elseif ($this->options['allow-whitespaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID);
            } elseif ($this->options['allow-spaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID);
            }
        }
        return $isValid;
    }
961546
def validate(self, value):
        
        try:
            # trap blank fields here
            if not self.blank or value:
                v = int(value)
                if v < 0:
                    return None
            return value
        except ValueError:
            return None
237641
def validate_to_one(self, value):
        

        if value.rid and self.typeness is int:
            validators.validate_int(value)

        if value.rid and not self.skip_exists:
            if not value.load():
                raise ValidationError(self.messages['exists'])
        return value