Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!