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

233
Vistas
Mails separated by comas - add check for mail length (JS regex)

I have a regex for emails:

const EMAIL = /[a-z0-9-_.+]+@[a-z0-9]+[a-z0-9-.]*\.[a-z0-9]{2,9}/;

And one for validating if they are separated by comas. I need it for input validation.

const COMAS = new RegExp(
  `^(?:${VALID_EMAIL.source}(?:, *)?)+$`,
  'i',
);

I wanted to add a condition that from now on the max length of the mail would be 50. I tried solutions from other SO threads, but non of them works for me. It works when there is just one mail in array, but for many it counts the length of all the strings in the array...

const VALID_EMAIL = /(?!.{51})[a-z0-9-_.+]+@[a-z0-9]+[a-z0-9-.]*\.[a-z0-9]{2,9}/;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You may use this regex with a negated character class:

const VALID_EMAIL = /(?![^,]{51})[-a-z0-9_.+]+@[a-z0-9]+[a-z0-9-.]*\.[a-z0-9]{2,9}/;

(?!.{51}) will fail the match if there are 51 of any characters in the input while (?![^,]{51}) will fail only if there are 51 non-comma characters in an email.

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