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

291
Views
RegEx expression maximum 14 digits and maximum 2 decimals

I'm trying to validate an input in Angular that can only have a maximum of 14 digits and a maximum of 2 decimals (comma separated)

The thing is that Debuggex is validating my expression as correct but in Angular doesn't work:

^[0-9]{0,14}(,?)[0-9]{1,2}$

Angular validator:


Validators.pattern(/^[0-9]{0,14}(,?)[0-9]{1,2}$/)

Debuggex Demo

What I need:

55555555555555,12 CORRECT (MAXIMUN 14 DIGITS AND MAXIMUM 2 DECIMALS)
55555555555555,1  CORRECT (MAXIMUM14 DIGITS AND 1 DECIMAL)
555555555555555,12 INCORRECT (15 DIGITS AND TWO DECIMALS)
5555555555,        INCORRECT (COMMA WITHOUT DECIMALS)

Tanks!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

14 Characters in length and 2 digits

html:

<html>
<body>
<input type="text" value="abcd1werty2gnv" id="in" placeholder="enter here"/>
<p id="txt"></p>
</body>
</html>

JS:

function foo() {
  const s = document.getElementById("in").value;
  const regex = /(\d)/g;
  let c = s.match(regex).length;
    let l = s.length;
    document.getElementById("txt").textContent = `length: ${l} digits: ${c}`;
}

enter image description here

about 4 years ago · Juan Pablo Isaza Report

0

Try this:

Validators.pattern(/^[0-9]{1,14}(,[0-9]{1,2})?$/)

That makes the comma including the decimal part optional.

about 4 years ago · Juan Pablo Isaza Report
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!