Number validation
Вернуться к: Validate (main package)
Number validation
This method validates numbers. Decimal or not, max and min.
This method takes two arguments:
-
A number.
-
An array of options (optional).
Various option are:
-
decimal (mixed) - Decimal chars or false when decimal not allowed. For example ",." to allow both "." and ",".
-
dec_prec (int) - Number of allowed decimals.
-
min (float) - Minimum value.
-
max (float) - Maximum value.
How to use Number Validation
Number Validation
The following example assumes that one wants to validate a number when decimals are allowed and decimal character is ".", and number of allowed decimals is 4.
<?php
require_once 'Validate.php';
if (Validate::number(8.0004, array('decimal' => '.', 'dec_prec' => 4))) {
echo 'Valid number';
}
?>
And the following one assumes that one wants to validate a decimal number with decimal character "," or "." while it's less than "-7" and greater than "-9".
<?php
require_once 'Validate.php';
$number = '-8,1';
if (Validate::number($number,
array('decimal' => '.,', 'min' => -9, 'max' => -7 ))) {
echo 'Valid';
} else {
echo 'Invalid';
}
?>
Вернуться к: Validate (main package)