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

298
Visualizações
How to allow use sign ' with regular expression?

At the momemnt I'm using this regular expression to validate address

(!/^[A-Za-z]/i.test(street))

When I use address like this - Esterwergen - it works.

But when I added the sign before the title - 'Esterwergen - it shows my error.

Ho I can modify my RegEx and allow to use this sign before the name?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

To allow an optional leading ', you'd change your regexp from

/^[A-Za-z]/

to

/^'?[A-Za-z]/

where the ? means "zero or one times".

If you want to allow the ' anywhere in your string,

/^['A-Za-z]/

would do the trick.

In addition, be sure that you realize that you're only checking the first character of the string as it is.

Right now you will allow Ester9ui4y6ewigkdlLNDSKJ#€=# :::.

To constrain that, you'll need the + quantifier and the $ (end-of-string) anchor.

/^[A-Za-z]+$/
about 4 years ago · Juan Pablo Isaza Relatório

0

Lets see what is your RegExp targeting:

  • /^[A-Za-z]/i

  • ^: Asserts position at start of the string.

  • []: Match a single character depending on what's inside.

  • A-Z: Match uppercase letters from A to Z.

  • a-z: Match lowercase letters from a to z.

  • i: Case-insensitive.

Consider this:

  • Using [A-Za-z] along with i flag is redundant. Use /^[a-z]/i or /^[A-z]/ instead.

  • Using [a-zA-Z\u00C0-\u00FF] for example extends matching to latin characters using UNICODE syntax. See full UNICODE reference here.

  • Use /^['a-z]+/i to allow ' anywhere in the string.

  • Use /^'?[a-z]+/i to allow ' only at the beginning of the string. ? means '1 time or 0 times'.

To play around with RegExp you can use tools like this.

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