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

511
Visualizações
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.]+)$/;
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Without more information I'd use

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

The negative lookahead prevents empty matches.

See this demo at regex101

about 4 years ago · Juan Pablo Isaza Relatório

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

about 4 years ago · Juan Pablo Isaza Relatório

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

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