neolodor
neolodor

Reputation: 85

Yii2 model rules match validation

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?

Upvotes: 0

Views: 317

Answers (1)

neolodor
neolodor

Reputation: 85

Escape with double slash fixes client side without crashing server side

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

Upvotes: 0

Related Questions