Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Regex Validator always return false in Form:(

Hello! Why regex validation doesn't work :( ```php // Surname $surname = new Text('surname', array( 'placeholder' => 'Не указано' )); $surname->setDefault($user_info->profile->surname); $surname->setLabel('Фамилия');

    $surname->addValidators([new Regex([

                'message' => 'Фамилия может содержать только символы латиницы или кирилицы',
                'pattern' => '/^[A-Za-zА-Яа-я]$/u'
            ]),
    ]);

``` And if I use regex with pattern '/^[0-9]$/' i also get FALSE and error message :(

Try

$surname->addValidators([new Regex([

          'message' => 'Фамилия может содержать только символы латиницы или кирилицы',
          'pattern' => 'pattern' => '/^[A-Za-zА-Яа-я]*$/'
        ]),
    ]);


8.8k
Accepted
answer

I solved this problem by changing regex pattern (added {1,}) to '/^[A-Za-zА-Яа-я]{1,}*$/'