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

372
Visualizações
Error in a regex accepting special characters

I'm using a regex to test the validity of a name. This is the code:

if (!/^[A-Za-zÀ-Ÿ- ]+$/.test(value)) {
  doSomething()
}

Unfortunately in the browser I get this error:

Uncaught SyntaxError: Invalid regular expression: /^[A-Za-zÀ-ȕ- ]+$/: Range out of order in character class.

The minified js has the code correctly compiled, but I load this .js file in .jsp file on my server. How does this influence the final messed up expression that I ended up with?

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

0

It appears as though the browser is interpreting the special characters in a character set other than utf-8. Make sure the web page is set to use utf-8 encoding.

<meta charset="utf-8">

Another idea to help with the regular expressions is to use unicode escaping. This may help with the encoding issue regardless of encoding.

You could replace the regex as such (assuming I have the character codes correct):

if (!/^[A-Za-z\u{c380}-\u{c5b8}- ]+$/.test(value)) {
  doSomething();
}

And if you wanted to check for - in your expression, probably escape it as well (\-).

if (!/^[A-Za-z\u{c380}-\u{c5b8}\- ]+$/.test(value)) {
  doSomething();
}
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