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

373
Vistas
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 Respuestas
Responde la pregunta

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 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