yii2 validation match regular expression pattern got invalid input

前端 未结 1 1583
一向
一向 2021-01-25 17:03

following the rule of thumb never to trust data received from end users before putting it to good use, i tried one of the core validators\' match. before placing it as pattern,

相关标签:
1条回答
  • 2021-01-25 17:58

    I guess what is really happening here is only client validation fails.

    This is because PHP regex engine is different from the JS one. If you are using regex101 service to check the expression you can test it by switching the flavor on the left side menu from pcre (php) to javascript. If pcre is ok then it works on the server side, if javascript is ok it also works on the client side.

    The solutions here are:

    • modify the pattern to work for JS,
    • switch client validation off,
    • prepare the rule to work only for server side (like using inline validator),
    • use AJAX validation.
    0 讨论(0)
提交回复
热议问题