Yii2 model rules match validation

273 views Asked by At

In model rules I have this rule:

[
  ['field1', 'field2,]
  'match',
  'pattern' => "/^[а-яА-ЯіІїЇєЄa-zA-Z\s\`\'\-\,]*$/u",
]

On form submit this rule works fine. But on client side it's not working. In console I see error:

Uncaught SyntaxError: Invalid regular expression: /^[а-яА-ЯіІїЇєЄa-zA-Z\s\`'-,]*$/: Invalid escape

Why this rule doesn't works on client side?

1

There are 1 answers

0
neolodor On BEST ANSWER

Escape with double slash fixes client side without crashing server side

[
  ['field1', 'field2,]
  'match',
  'pattern' => "/^[а-яА-ЯіІїЇєЄa-zA-Z\s\\\`\\\'-\\\,]*$/u",
]