Partial matching a string against a regex

前端 未结 6 1765
梦毁少年i
梦毁少年i 2021-02-04 01:02

Suppose that I have this regular expression: /abcd/ Suppose that I wanna check the user input against that regex and disallow entering invalid characters in the input. When user

6条回答
  •  生来不讨喜
    2021-02-04 01:48

    As many have stated there is no standard library, fortunately I have written a Javascript implementation that does exactly what you require. With some minor limitation it works for regular expressions supported by Javascript. see: incr-regex-package.

    Further there is also a react component that uses this capability to provide some useful capabilities:

    1. Check input as you type
    2. Auto complete where possible
    3. Make suggestions for possible input values

    Demo of the capabilities Demo of use

提交回复
热议问题