re: Regex Bootcamp (or Nobody Seems to be Using HTML5 Validation) VIEW POST


"you cannot assign a regex defined as a literal to a variable"

I'm not sure if I got this right and could probably a stupid question. But by saying you cannot assign, do you mean that the following is invalid or frowned upon?

const myRegex = /^\d{0,5}$/;

Hmm I could be wrong I was trying something like this but it was barfing on the \d I think, as soon as I used new RegExp and escaped the \d with a slash it worked.

code of conduct - report abuse