<?php


namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Validators;


use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Validators\BaseValidator;

class SearchdomainValidator extends BaseValidator
{

    protected function validate($data, $additionalData = null)
    {
        if($additionalData->get('formData')['osTemplate'] && $additionalData->get('formData')['osTemplate']=='installationFromIso' ){
            return true;
        }
        if (empty($data))
        {
            return true;
        }
        if (!preg_match('/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/', $data))
        {
            $this->addValidationError('PleaseProvideASearchdomain');
            return false;
        }
        return true;
    }
}