Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
String Variable To Regular Expression Java Script

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/

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!