I am having a regex where i check the input is having 6 digit number. I am able to achieve it with the below refgex
/^\d{6}$/gm.test("123456")
I have used this regex in multiple places so I am trying to make it as a function
function testNumber(number, digitLength = 6){
return /^\d{6}$/gm.test(number)
}
Now in some places the digitLength is of 3 and in some places its 4, now how can i interpolate the digitLength in the regex so i can pass as much the digitLength instead of hardcoding 6 in the regex.
Any help is appreciated