0

My regex validates words (also containing numbers), but words that have accents are not validating correctly.

/^[a-zA-Z0-9_]*$/i.test(word)

For example:

car => true

plantas => true

avião => false (but this should be also true)

What should I change in my regex to also work with accents?

johnnyRose
  • 7,310
  • 17
  • 40
  • 61
  • 1
    Just add the characters that you want to be validated: ex `[\wáéíóúâêîôû]*$/i` – ElChiniNet Apr 24 '17 at 11:57
  • 1
    _"Since regular expressions are not fully standardized, all questions with this tag should also include a tag specifying the applicable programming language or tool."_ Is this Javascript? – Aran-Fey Apr 24 '17 at 11:57
  • @ElChiniNet How do I add this to the current regex? –  Apr 24 '17 at 11:59
  • 2
    @IbnClaudius: That is supposed to *replace* yours - like `/^[\wáéíóúâêîôûã]*$/i`. Just add the chars you need to the character class. – Wiktor Stribiżew Apr 24 '17 at 12:01
  • 1
    This is javascript? – chris85 Apr 24 '17 at 12:09
  • I had the same issue with Greek and I defined character range with help from [https://unicode-table.com/en/](https://unicode-table.com/en/). For example: `[a-zA-ZΆΈ-ώἀ-ῼ]*` – tgogos Apr 24 '17 at 12:47
  • Yes, its javascript! –  Apr 24 '17 at 14:52

0 Answers0