|
| 1 | +# GreaterThanOrEqual |
| 2 | + |
| 3 | +Validates that a value is greater than or equal to another value. Can compare between strings, numbers and dates. |
| 4 | + |
| 5 | +## Basic Usage |
| 6 | + |
| 7 | +```php |
| 8 | +Validator::greaterThan(10)->validate(20); // true |
| 9 | +Validator::greaterThan(10)->validate(10); // true |
| 10 | +Validator::greaterThan(1.5)->validate(2.5); // true |
| 11 | +Validator::greaterThan(1.5)->validate(1.5); // true |
| 12 | +Validator::greaterThan('alpha')->validate('beta'); // true |
| 13 | +Validator::greaterThan('alpha')->validate('alpha'); // true |
| 14 | +Validator::greaterThan(new DateTime('today'))->validate(new DateTime('tomorrow')); // true |
| 15 | +Validator::greaterThan(new DateTime('today'))->validate(new DateTime('today')); // true |
| 16 | +``` |
| 17 | + |
| 18 | +> **Note** |
| 19 | +> String comparison is case-sensitive, meaning that comparing `'hello'` with `'Hello'` is different. |
| 20 | +> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information. |
| 21 | +
|
| 22 | +> **Note** |
| 23 | +> An `UnexpectedValueException` will be thrown when trying to compare incomparable values, like a `string` with an `int`. |
| 24 | +
|
| 25 | +## Options |
| 26 | + |
| 27 | +### `constraint` |
| 28 | + |
| 29 | +type: `mixed` `required` |
| 30 | + |
| 31 | +It defines the comparison/minimum value. Can be a `string`, `int`, `float` or `DateTimeInterface` object. |
| 32 | + |
| 33 | +### `message` |
| 34 | + |
| 35 | +type: `string` default: `The "{{ name }}" value should be greater than or equal to "{{ constraint }}", "{{ value }}" given.` |
| 36 | + |
| 37 | +Message that will be shown if the value is not greater than or equal to the constraint value. |
| 38 | +Check the [Custom Messages]() section for more information. |
| 39 | + |
| 40 | +The following parameters are available: |
| 41 | + |
| 42 | +| Parameter | Description | |
| 43 | +|--------------------|------------------------------------| |
| 44 | +| `{{ value }}` | The current invalid value | |
| 45 | +| `{{ name }}` | Name of the value being validated | |
| 46 | +| `{{ constraint }}` | The comparison/minimum value | |
0 commit comments