Answer the question
In order to leave comments, you need to log in
How to pass a regular expression to the pattern attribute of an input?
Good evening, I have an input component. This class has a field with all the regular expressions I need:
regexp = {
username: /^[a-zа-я0-9_-]{2,16}$/,
password: /^.{6,18}$/,
email: /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
noRegexp: /./
}
<input
...={ ... }
pattern={ this.regexp[regexpName].toString().replace( /\//g, '' ) }
...={ ... }
/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question