Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda