mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
This commit will do many different things, but they are all improvements to the "Ip" rules: * Remove passing variables by reference: the "Ip" class uses that a lot to define the start address, end address, and the mask used to validate a network range; * Remove double-typed argument from the constructor: the class "Ip" class has only one argument that can be either a string with the range of the IP or an integer with options for the "filter_var()" function. This commit will split it into two different arguments, each of them used for one of this functionalities; * Update documentation to show how to validate IPv6. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
44 lines
976 B
Markdown
44 lines
976 B
Markdown
# Ip
|
|
|
|
- `Ip()`
|
|
- `Ip(string $range)`
|
|
- `Ip(string $range, int $options)`
|
|
|
|
Validates whether the input is a valid IP address.
|
|
|
|
This validator uses the native [filter_var()][] PHP function.
|
|
|
|
```php
|
|
v::ip()->validate('127.0.0.1'); // true
|
|
v::ip('220.78.168.0/21')->validate('220.78.173.2'); // true
|
|
v::ip('220.78.168.0/21')->validate('220.78.176.2'); // false
|
|
```
|
|
|
|
You can pass a parameter with [filter_var()][] flags for IP.
|
|
|
|
```php
|
|
v::ip('*', FILTER_FLAG_NO_PRIV_RANGE)->validate('192.168.0.1'); // false
|
|
```
|
|
|
|
If you want to validate IPv6 you can do as follow:
|
|
|
|
```php
|
|
v::ip('*', FILTER_FLAG_IPV6)->validate('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'); // true
|
|
```
|
|
|
|
## Changelog
|
|
|
|
Version | Description
|
|
--------|-------------
|
|
2.0.0 | Allow to define range and options to the same instance
|
|
0.5.0 | Implemented IP range validation
|
|
0.3.9 | Created
|
|
|
|
***
|
|
See also:
|
|
|
|
- [Domain](Domain.md)
|
|
- [MacAddress](MacAddress.md)
|
|
- [Tld](Tld.md)
|
|
|
|
[filter_var()]: https://php.net/filter_var
|