Validating numeric data
Namespace: Sphp \ Validators
Numeric data validators validate float values and int values and numeric strings.
A PHP string is considered numeric if it can be interpreted as an int
or a float [1] .
Validators:
SmallerThan is lower bound validator: the length of the input must be atleast a given limit.
GreaterThan is upper bound validator: the length of the input must be below a given limit.
Between validator: value must be between the lower and upper limits.
Predefined errormessage Template formatting parameters:
:value - the string representation of the validated $value
:type - the datatype of the validated $value
:type = "boolean" - for boolean type
:type = "integer" - for integer type
:type = "float" - for float type
:type = "string" - for string type
:type = "array" - for array type
:type = "object" - for object type
:type = "resource" - for resource type
:type = "resource (closed)" - for closed resource type
:type = "NULL" - for nulls
:type = "unknown type" - for unknown types
:strict-type - the strict datatype of the validated $value differs from :type
any object corresponds to the name of the class get_class() results
The Between validator validates whether numeric input is between two numbers. This range is either inclusive or exclusive.
Validator specific predefined errormessage Template formatting parameters:
:min - the minumum allowed value of the validated $value
:max - the maximum allowed value of the validated $value
Synopsis
ID for error message describing values not matching an exclusive limit
public const string INVALID_TYPE ID for default error message
public const string INVALID Constructs a new validator
public __construct ( float $min ,
float $max ,
bool $inclusive = true ) Validates given value
public isValid ( mixed $value ) : bool
Checks whether the the limit is set as inclusive or not
public isInclusive ( ) : bool
Invoke validator as a command
public __invoke ( mixed $value ) : bool
The SmallerThan validator validates whether a float or an int input is msaller than or equal to a treshold value.
Validator specific predefined errormessage Template formatting parameters:
:max - the maximum allowed value of the validated $value
Synopsis
ID for error message describing values not matching an exclusive limit
public const string INVALID_TYPE ID for default error message
public const string INVALID Constructs a new validator
public __construct ( float $max ,
bool $inclusive = true ) Validates given value
public isValid ( mixed $value ) : bool
Checks whether the the limit is set as inclusive or not
public isInclusive ( ) : bool
Invoke validator as a command
public __invoke ( mixed $value ) : bool
The GreaterThan validator validates whether a float or an int input is greater than or equal to a treshold value.
Validator specific predefined errormessage Template formatting parameters:
:min - the minumum allowed value of the validated $value
Synopsis
ID for error message describing values not matching an exclusive limit
public const string INVALID_TYPE ID for default error message
public const string INVALID Constructs a new validator
public __construct ( float $min ,
bool $inclusive = true ) Validates given value
public isValid ( mixed $value ) : bool
Checks whether the the limit is set as inclusive or not
public isInclusive ( ) : bool
Invoke validator as a command
public __invoke ( mixed $value ) : bool
References