create client side form validator

@param \Antares\Contracts\Html\Grid $grid
@return array
341050
public function addClientValidation(&$grid)
    {
        $rules = $grid->rules;
        $form  = $grid->attributes;
        if (!array_key_exists('id', $form)) {
            $id         = $this->generateID();
            $grid->attributes(array_merge($form, ['id' => $id]));
            $form['id'] = $id;
        }
        if (!empty($rules)) {
            $form['data-toggle'] = "validator";
            $this->attachScripts();
            $this->attachRules($grid, $rules);
        }


        if ($grid->ajaxable !== false) {
            $this->ajaxValidation->build($grid);
        }

        return ['form' => $form, 'fieldsets' => $grid->fieldsets()];
    }
472766
public function grid(): array
    {
        return [
            TD::set('id', 'ID')
                ->align(TD::ALIGN_CENTER)
                ->width('100px')
                ->filter('numeric')
                ->sort()
                ->linkPost(),

            TD::set('name', 'Name')
                ->width('250px')
                ->locale()
                ->column('content.name')
                ->filter('text')
                ->sort()
                ->linkPost('name'),

            TD::set('status')
                ->sort(),

            TD::set('phone', 'Phone')
                ->locale()
                ->column('content.phone')
                ->filter('text')
                ->linkPost('phone'),

            TD::set('publish_at', 'Date of publication')
                ->filter('date')
                ->sort()
                ->align(TD::ALIGN_RIGHT)
                ->render(function ($item) {
                    return optional($item->publish_at)->toDateString();
                }),

            TD::set('created_at', 'Date of creation')
                ->filter('date')
                ->align(TD::ALIGN_RIGHT)
                ->sort()
                ->render(function ($item) {
                    return $item->created_at->toDateString();
                }),
        ];
    }
645838
public function validate(array $array)
	{
		$messages = [];
		foreach ($this->metadata->fields as $field)
		{
			$value = array_key_exists($field, $array)? $array[$field] : null;
			if (!(($value === null) && $this->metadata->nullables[$field]))
			{
				$validator = $this->getValidator($field);
				if (!$validator->isValid($value))
				{
					$messages[$field] = $validator->getMessages();
				}
			}
		}
		$globalValidator = $this->getValidator(self::GLOBAL_VALIDATOR_KEY);
		if (!$globalValidator->isValid($array))
		{
			$messages[self::GLOBAL_VALIDATOR_KEY] = $globalValidator->getMessages();
		}
		return $messages;
	}
164703
public function validate(): array
	{
		if($this->isInvalid())
		{
			throw new ValidationException($this->errors, 'Invalid input.');
		}

		$validated = [];

		foreach(array_keys($this->ruleSets) as $validatedKey)
		{
			if(Arr::has($this->input, $validatedKey))
			{
				Arr::set($validated, $validatedKey, Arr::get($this->input, $validatedKey));
			}
		}

		return $validated;
	}
1154431
protected function validator(array $data)
    {
        $user = Auth::user();

        $rules = [
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users,email,' . $user->id,
        ];

        if ($data['password'] !== null) {
            $rules['password'] = 'required|string|min:6|confirmed';
        }

        return Validator::make($data, $rules);
    }
952057
public function initialize(Grid $grid)
    {
        $this->initializeComponent($grid);
        $this->provideFields();
        $this->listen(
            $this->grid->getConfig()->getDataProvider()
        );
        return null;
    }
911881
protected function validate(array $rules, bool $throwError = true)
    {
        $validations = [];
        $data = [];
        foreach ($rules as $key => $rule) {
            $value = $this->request->get($key);
            $violations = $this->validator->validate($value, $rule);
            if (count($violations) > 0) {
                $validations[$key] = [];
                foreach ($violations as $violation) {
                    $validations[$key][] = $violation->getMessage();
                }
            } else {
                $data[$key] = $value;
            }
        }
        if ($throwError && count($validations)) {
            throw new HttpValidationException($validations);
        }
        return $data;
    }
523178
public function getClassesCreate($grid)
    {
        // Get explicit or fallback class list
        $classes = $this->getClasses();
        if (empty($classes) && $grid) {
            $classes = array($grid->getModelClass());
        }

        // Filter out classes without permission
        return array_filter($classes, function ($class) {
            return singleton($class)->canCreate();
        });
    }
275233
public function config_form_validation(array $data, $files = array()) : array {
        $options = preg_split("/\s*\n\s*/", trim($data['configdata']['options']));
        $errors = [];
        if (!$options || count($options) < 2) {
            $errors['configdata[options]'] = get_string('errornotenoughoptions', 'customfield_select');
        } else if (!empty($data['configdata']['defaultvalue'])) {
            $defaultkey = array_search($data['configdata']['defaultvalue'], $options);
            if ($defaultkey === false) {
                $errors['configdata[defaultvalue]'] = get_string('errordefaultvaluenotinlist', 'customfield_select');
            }
        }
        return $errors;
    }
211503
private function validateRows($rows)
    {
        if ($rows === false)
            return $rows;
        if (empty($rows))
            return $rows ?: [];
        foreach($rows as $e=>$r){

            $rows[$e] = $this->validateRow($r);
        }
        return $rows;

    }
834817
private function validateColumn($column)
    {
        if ($column === false)
            return $column;
        $resolver = new OptionsResolver();
        $resolver->setDefaults([
            'form' => false,
            'label' => false,
            'label_params' => [],
            'class' => false,
            'buttons' => false,
            'container' => false,
            'rows' => false,
            'collection_actions' => false,
            'style' => false,
            'onClick' => false, 
        ]);
        $resolver->setAllowedTypes('class', ['boolean','string']);
        $resolver->setAllowedTypes('buttons', ['boolean','array']);
        $resolver->setAllowedTypes('label', ['boolean', 'string']);
        $resolver->setAllowedTypes('label_params', ['array']);
        $resolver->setAllowedTypes('container', ['boolean', 'array']);
        $resolver->setAllowedTypes('rows', ['boolean', 'array']);
        $resolver->setAllowedTypes('style', ['boolean', 'array']);
        $resolver->setAllowedTypes('onClick', ['boolean', 'array']);
        $resolver->setAllowedTypes('form', ['array', 'boolean']);
        $resolver->setAllowedTypes('collection_actions', ['boolean']);
        $column = $resolver->resolve($column);

        if ($column['rows'] && $column['container'])
            trigger_error(sprintf('A column must not have a container and rows assign. Choose either container or rows or neither.'), E_USER_ERROR);

        $column['container'] = $this->validateContainer($column['container']);
        $column['rows'] = $this->validateRows($column['rows']);
        $column['onClick'] = $this->validateUrl($column['onClick']);
        $column['buttons'] = $this->validateButtons($column['buttons']);
        if (is_array($column['form']))
            $this->addFormTabMap(key($column['form']));

        $column['label'] = $column['label'] ? $this->getTranslator()->trans($column['label'], $column['label_params'], $this->getTranslationDomain()) : false;

        return $column;
    }
1017472
public function validate(string $password): array
    {
        $errors = [];

        if (!$this->isLongEnough($password)) {
            $errors[] = $this->createValidationError('User password must be at least %length% characters long', [
                '%length%' => $this->constraints['minLength'],
            ]);
        }

        if (!$this->containsAtLeastOneLowerCaseCharacter($password)) {
            $errors[] = $this->createValidationError('User password must include at least one lower case letter');
        }

        if (!$this->containsAtLeastOneUpperCaseCharacter($password)) {
            $errors[] = $this->createValidationError('User password must include at least one upper case letter');
        }

        if (!$this->containsAtLeastOneNumericCharacter($password)) {
            $errors[] = $this->createValidationError('User password must include at least one number');
        }

        if (!$this->containsAtLeastOneNonAlphanumericCharacter($password)) {
            $errors[] = $this->createValidationError('User password must include at least one special character');
        }

        return $errors;
    }
1011214
protected function validate(array $item)
    {
        $object = $this->objectFactory->factor($item);
        $list = $this->validator->validate($object);

        return $list;
    }
593293
public function instance_form_validation(array $data, array $files) : array {
        $errors = parent::instance_form_validation($data, $files);
        if ($this->get_field()->get_configdata_property('required')) {
            // Standard required rule does not work on select element.
            $elementname = $this->get_form_element_name();
            if (empty($data[$elementname])) {
                $errors[$elementname] = get_string('err_required', 'form');
            }
        }
        return $errors;
    }
450764
public function buildDataGridForm(
        Action $action,
        Request $request,
        DataGrid $dataGrid = null,
        array $formOptions = []
    ): DataGrid {
        if (null === $dataGrid) {
            $dataGrid = $this->getDataGrid($action);
        }
        $formOptions = array_merge(
            [
                'method' => $this->method,
                'csrf_protection' => false,
                'action' => $this->routingHelper->getCurrentUri($action, $request),
                'validation_groups' => ['filters'],
            ],
            $formOptions
        );

        // Create form with filters
        $builder = $this->formFactory->createBuilder(FormType::class, null, $formOptions);
        $dataGrid->buildForm($builder);

        return $dataGrid;
    }
1016503
private function validateColumns($columns): array
    {
        foreach($columns as $e=>$r){
            $columns[$e] = $this->validateColumn($r);
        }
        return $columns;

    }
310492
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(!$exists) {
            return false;
        }
        
        $n = \explode(',', $options);
        if(!\in_array($value, $n)) {
            return array('formvalidator_make_in', array('{0}' => $options));
        }
        
        return true;
    }