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

569
Vistas
how can I limit dot only once or optional in regex

A regex is needed which should have only special character dot which should either be optional or occur only once.

pattern = /^([A-Za-z.]+)$/;
over 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Without more information I'd use

/^(?!$)[a-z]*\.?[a-z]*$/i

The negative lookahead prevents empty matches.

See this demo at regex101

over 4 years ago · Juan Pablo Isaza Denunciar

0

Here are some ways to do it:

  1. Deal separately where the input has has one dot, with optional letters surrounding it, or no dot (but then having at least one letter):

    /^([a-z]*\.[a-z]*|[a-z]+)$/i

  1. Just capture letters and dots like you did, but don't allow the input to have two dots, using a negative look ahead:

    /^(?!(.*\.){2})([a-z.]+)$/i

  2. Capture optional letters then an optional point and then optional letters, but forbid an empty input with a negative look-ahead:

    /^(?!$)([a-z]*\.?[a-z]*)$/i

over 4 years ago · Juan Pablo Isaza Denunciar

0

If in any case the dot should not be at the start or end and not match an empty string, you can start the match with 1 or more chars a-z and then optionally match a dot and again 1 or more chars a-z:

/^[a-z]+(?:\.[a-z]+)?$/i

Regex demo

over 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
Asistente virtual