[[+content_image]]
W
W
WildJust2016-12-01 21:17:42
Yii
WildJust, 2016-12-01 21:17:42

Who can help with Yii2 regex validation?

Here is the actual code:

return [
            [['product_id'], 'required'],
            [['product_id', 'views'], 'integer'],
            [['description'], 'string'],
            [['rating', 'price'], 'number'],
            [['title', 'image'], 'string', 'max' => 255],
            ['title',  'match', 'pattern' => '/^[а-яА-ЯёЁ0-9/s]+$/'],
        ];

The problem is in the title field, there should be only Cyrillic, numbers and a space. Ajax validation skips, after clicking on save, saving does not occur and title is invalid.
I tried to remove the $, then everything is saved, but it also skips the Latin alphabet. Help pliz.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dmitry, 2016-12-01
@WildJust

Good evening.
To get started, try this:
'/^[а-яё0-9 ]+$/iu'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question