Skip to content

NumberValidator

NumberValidator verifies that a parameter is a number and allows you to apply size constraints.

Parameters: ‘no_locale’ do not use localized number format parsing with translation on ‘in_locale’ locale to use for parsing rather than the current locale ‘type’ number type (int/integer or double/float) ‘cast_to’ type to cast to (int/integer or double/float) ‘min’ minimum value for the input ‘max’ maximum value for the input

class NumberValidator extends Validator

ExtendsValidator
Since1.0.0
SourceValidator/NumberValidator.php
MethodDescription
getAcceptedParameters(): array<int, string>Returns the base Validator parameters plus ‘no_locale’, ‘in_locale’, ‘type’, ‘cast_to’, ‘min’ and ‘max’.

public static function getAcceptedParameters(): array<int, string>

Returns the base Validator parameters plus ‘no_locale’, ‘in_locale’, ‘type’, ‘cast_to’, ‘min’ and ‘max’.

A string input is parsed through DecimalFormatter in the current locale when translation is enabled; ‘no_locale’ forces locale-less parsing and ‘in_locale’ names a specific locale to parse in instead of the current one. ‘type’ constrains what the parsed value must be — ‘int’/‘integer’ or ‘float’/‘double’, anything else meaning any number — and ‘min’/‘max’ bound its value, each checked only when present. ‘cast_to’ selects the type the value is cast to before it is exported (or written back into the request parameters when no ‘export’ is configured); it defaults to ‘type’.

Returns array``<``int``, ``string``> — The accepted parameter names.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
execute()ValidatorExecutes the validator.
getArguments()ValidatorReturns all arguments which should be validated.
getBase()ValidatorReturns the base path of this validator.
getBaseKeys()ValidatorReturns the “keys” in the path of the base
getContext()ValidatorRetrieve the current application context.
getDependencyManager()ValidatorReturns the depency manager of the parent container if any.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getLastKey()ValidatorReturns the last “keys” in the path of the base
getMutatedRequest()ValidatorThe WebRequest this validator ended execute() with.
getName()ValidatorReturns the name of this validator.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
getParentContainer()ValidatorRetrieve the parent container.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
initialize()ValidatorInitialize this validator.
mapErrorCode()ValidatorConverts string severity codes into integer values (see severity constants) critical -> Validator::CRITICAL error -> Validator::ERROR notice -> Validator::NOTICE none -> Validator::NONE success -> not allowed to be specified by the user.
removeParameter()ParameterHolderRemove a parameter.
reset()ValidatorReturns the validator to its uninitialized state for reuse across requests.
setErrorMessage()ValidatorSets an error message override for the given index (the empty string is the default/generic message).
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.
setParentContainer()ValidatorSets the parent container.
shutdown()ValidatorShuts the validator down.