http://modulesgarden.com * CONTACT -> contact@modulesgarden.com * * * This software is furnished under a license and may be used and copied * only in accordance with the terms of such license and with the * inclusion of the above copyright notice. This software or any other * copies thereof may not be provided or otherwise made available to any * other person. No title to and ownership of the software is hereby * transferred. * * * ******************************************************************** */ namespace ModulesGarden\ProxmoxAddon\App\UI\Validators; use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Validators\BaseValidator; /** * Description of NumberValidator * * @author Pawel Kopec */ class IpAddressAndHostnameValidator extends BaseValidator { protected $required = false; protected $public = true; public function __construct($required = false, $public = true) { $this->required = $required; $this->public = $public; } protected function validate($data, $additionalData = null) { if (!$this->required && empty($data)) { return true; } $ip = filter_var($data, FILTER_VALIDATE_IP); $url = filter_var($data, FILTER_VALIDATE_URL); $host = filter_var($data, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME); if ( !$ip && !$url && !$host) { $this->addValidationError('The value is not valid', false); return false; } return true; } }