From d81e18504166f58c08d30ab533300a61d4e94d45 Mon Sep 17 00:00:00 2001 From: Marcel Naeve Date: Thu, 12 May 2016 17:04:31 +0200 Subject: [PATCH] added ip(v4+v6) validation methods. --- Validate.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Validate.php b/Validate.php index 2156d33..919174e 100644 --- a/Validate.php +++ b/Validate.php @@ -58,4 +58,34 @@ class Validate return $results; } + + /** + * Static function for validating a IP Address. + * @param string $address IP address + * @return bool is the IP Address valid? + */ + static function ip(string $address) : bool + { + return false !== filter_var($address, FILTER_VALIDATE_IP); + } + + /** + * Static function for validating a IPv4 Address. + * @param string $address IPv4 address + * @return bool is the IPv4 Address valid? + */ + static function ipv4 (string $address) : bool + { + return false !== filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); + } + + /** + * Static function for validating a IPv6 Address. + * @param string $address IPv6 address + * @return bool is the IPv6 Address valid? + */ + static function ipv6 (string $address) : bool + { + return false !== filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); + } } \ No newline at end of file