Check if string is a prefix of a Javascript RegExp

后端 未结 5 2136
旧巷少年郎
旧巷少年郎 2021-01-04 03:31

In Javascript I have defined a regular expression and now a user is typing in a string. I want to tell him if his string still could match the RegExp if he continues typing

5条回答
  •  误落风尘
    2021-01-04 04:16

    First you define your regular expression as: var re = new RegExp(/^(regexp here)$/);

    on the onKeypress event, you check the regexp like this:

    text.match(regexp) - where the text is the string entered.

    Is this clear?

提交回复
热议问题