mirror of
https://github.com/YGGverse/net-php.git
synced 2026-03-31 09:05:34 +00:00
implement validation class
This commit is contained in:
parent
f6a3b1bbfa
commit
b37f28ce4f
1 changed files with 40 additions and 0 deletions
40
src/Valid.php
Normal file
40
src/Valid.php
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Net;
|
||||||
|
|
||||||
|
class Valid
|
||||||
|
{
|
||||||
|
public static function ip(mixed $value): bool
|
||||||
|
{
|
||||||
|
return self::ip4($value) || self::ip6($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function ip4(mixed $value): bool
|
||||||
|
{
|
||||||
|
return false !== filter_var(
|
||||||
|
$value,
|
||||||
|
FILTER_VALIDATE_IP,
|
||||||
|
FILTER_FLAG_IPV4
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function ip6(mixed $value): bool
|
||||||
|
{
|
||||||
|
return false !== filter_var(
|
||||||
|
$value,
|
||||||
|
FILTER_VALIDATE_IP,
|
||||||
|
FILTER_FLAG_IPV6
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function domainHostName(mixed $value): bool
|
||||||
|
{
|
||||||
|
return false !== filter_var(
|
||||||
|
$value,
|
||||||
|
FILTER_VALIDATE_DOMAIN,
|
||||||
|
FILTER_FLAG_HOSTNAME
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue