I have a regular expression defined as a string that I want to evaluate against an input string, for example:
let myVal = "22.00";
let strReg = "^\d*\.?\d{0,2}$";
let regex = new RegExp(strReg);
if (myVal.match(regex)){
console.log("It's a valid two decimal place number")
} else {
console.log("It's invalid")
}
If I change the expression to "^\\d*\\.?\\d{0,2}$" then it works.
My question is how can I format strReg using javascript, so it evaluates correctly. Example code here https://jsfiddle.net/h0795vte/