note 124876 added to filter.filters.validate
| From: | MRYekta@php.net | Date: | Thu, 02 Apr 2020 22:17:53 +0000 |
| Subject: | note 124876 added to filter.filters.validate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214409@lists.php.net to get a copy of this message | ||
since php 7.4
you can use these 3 beautiful conditions for from validation for validation less, great or in range
<?php
/**
* less_than_equal_to
*/
$x = 50;
if (filter_var($x, FILTER_VALIDATE_FLOAT, ["options" => ["max_range" =>
100]]) !== false) {
echo "result : $x is less than OR equal to 100";
} else {
echo "result : $x is NOT less than OR equal to 100";
}
?>
result : 50 is less than OR equal to 100
<?php
/**
* greater_than_equal_to
*/
$x = 50;
if (filter_var($x, FILTER_VALIDATE_FLOAT, ["options" => ["min_range" =>
100]]) !== false) {
echo "result : $x is greater than OR equal to 100";
} else {
echo "result : $x is NOT greater than OR equal to 100";
}
?>
result : 50 is NOT greater than OR equal to 100
<?php
/**
* less_than_equal_to && greater_than_equal_to
*/
$x = 50;
if (filter_var($x, FILTER_VALIDATE_FLOAT, ["options" => ["min_range" => 0
, "max_range"=> 100]]) !== false) {
echo "result : $x is in range of 0 to 100";
} else {
echo "result : $x in NOT range of 0 to 100";
}
?>
result : 50 is in range of 0 to 100
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.195 (proxied: 2.179.221.83)
----
Manual Page -- http://php.net/manual/en/filter.filters.validate.php
Edit -- https://master.php.net/note/edit/124876
Del: integrated -- https://master.php.net/note/delete/124876/integrated
Del: useless -- https://master.php.net/note/delete/124876/useless
Del: bad code -- https://master.php.net/note/delete/124876/bad+code
Del: spam -- https://master.php.net/note/delete/124876/spam
Del: non-english -- https://master.php.net/note/delete/124876/non-english
Del: in docs -- https://master.php.net/note/delete/124876/in+docs
Del: other reasons-- https://master.php.net/note/delete/124876
Reject -- https://master.php.net/note/reject/124876
Search -- https://master.php.net/manage/user-notes.php