Angular regex test not consistent ng-pattern validation on input

后端 未结 1 1468
遇见更好的自我
遇见更好的自我 2021-01-21 16:04

I have a ng-pattern validation on my input

ng-pattern=\"/^(.+)$/g\"

This does not work the same everytime. And shows very weird behaviour.

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 16:42

    You must remove the /g from the regex, see updated plunkr.

    According to the docs:

    Note: Avoid using the g flag on the RegExp, as it will cause each successive search to start at the index of the last search's match, thus not taking the whole input value into account.

    0 讨论(0)
提交回复
热议问题