V
V
Vladimir2022-04-17 19:32:48
PHP
Vladimir, 2022-04-17 19:32:48

How to validate the language in a form field in yii2?

There is a field

<?= $form->field($model, 'name')->label('Имя')->textInput(['placeholder' => 'Ваше имя'])?>

And the settings for it require +Restriction on the number of characters. from 3 to 16.
What setting should be applied so that the name cannot be written in 2 languages. Only the English or Russian version, it will also be more correct.
Since if you write for example NameTest534 = it protects,

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Ivan., 2022-04-17
@faradeifrontend

In the rules of the form model, specify validation rules like this ( documentation ):

[
            [['name'], 'required'],
            [['name'], 'string', 'min' => 3, 'max' => 16],
            [['name'], 'match', 'pattern' => '<regex_rule>']
]

Specify the required regular expression in regex_rule , here you can create and test it

M
Mylistryx, 2022-04-19
@Mylistryx

the answer above is correct, well, as a variant of scenarios - on language===... and let's go, but the answer above is more universal, although it can be beaten into scenarios.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question