Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda