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
Synopsis
Section titled “Synopsis”class NumberValidator extends Validator
| Extends | Validator |
| Since | 1.0.0 |
| Source | Validator/NumberValidator.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
getAcceptedParameters(): array<int, string> | Returns the base Validator parameters plus ‘no_locale’, ‘in_locale’, ‘type’, ‘cast_to’, ‘min’ and ‘max’. |
getAcceptedParameters()
Section titled “getAcceptedParameters()”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.
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
appendParameter() | ParameterHolder | Append a parameter. |
appendParameterByRef() | ParameterHolder | Append a parameter by reference. |
clearParameters() | ParameterHolder | Clear all parameters associated with this request. |
execute() | Validator | Executes the validator. |
getArguments() | Validator | Returns all arguments which should be validated. |
getBase() | Validator | Returns the base path of this validator. |
getBaseKeys() | Validator | Returns the “keys” in the path of the base |
getContext() | Validator | Retrieve the current application context. |
getDependencyManager() | Validator | Returns the depency manager of the parent container if any. |
getFlatParameterNames() | ParameterHolder | Retrieve an array of flattened parameter names. |
getLastKey() | Validator | Returns the last “keys” in the path of the base |
getMutatedRequest() | Validator | The WebRequest this validator ended execute() with. |
getName() | Validator | Returns the name of this validator. |
getParameter() | ParameterHolder | Retrieve a parameter. |
getParameterNames() | ParameterHolder | Retrieve an array of parameter names. |
getParameters() | ParameterHolder | Retrieve an array of parameters. |
getParentContainer() | Validator | Retrieve the parent container. |
hasParameter() | ParameterHolder | Indicates whether or not a parameter exists. |
initialize() | Validator | Initialize this validator. |
mapErrorCode() | Validator | Converts 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() | ParameterHolder | Remove a parameter. |
reset() | Validator | Returns the validator to its uninitialized state for reuse across requests. |
setErrorMessage() | Validator | Sets an error message override for the given index (the empty string is the default/generic message). |
setParameter() | ParameterHolder | Set a parameter. |
setParameterByRef() | ParameterHolder | Set a parameter by reference. |
setParameters() | ParameterHolder | Set an array of parameters. |
setParametersByRef() | ParameterHolder | Set an array of parameters by reference. |
setParentContainer() | Validator | Sets the parent container. |
shutdown() | Validator | Shuts the validator down. |