0

All I want to do is allow A-Za-z0-9, including foreign alphabetic characters like ñ, í, ö, etc. I read that it is indeed possible to do this with the Unicode flag. Hence my expression:

re = /^[A-Za-z0-9]+$/u

However, it won't match any of the foreign characters above, which are the only ones I've tested. I suspect it won't match any foreign character at all.

Is there any way to include all or most foreign characters?

oldboy
  • 5,729
  • 6
  • 38
  • 86
  • Take a look at this post: https://stackoverflow.com/a/3010005 Foreign characters are actually two Unicode characters. – Skylar Oct 07 '19 at 02:15
  • @Skylar beautiful. i believe that works. if you want to make a post containing the info it points to ill select it as the answer!! – oldboy Oct 07 '19 at 02:19

2 Answers2

2

I'm guessing that, maybe

^(?:[A-Za-z0-9]|[^\x00-\x7F])+$

or a derivative of that might work, if you'd like to have browser compatibility.

Otherwise,

^[\p{L}]+$

might simply work.

Source

Unicode Regular Expressions

Community
  • 1
  • 1
Emma
  • 27,428
  • 11
  • 44
  • 69
  • 2
    Emma's right: https://caniuse.com/#feat=mdn-javascript_builtins_regexp_property_escapes – Skylar Oct 07 '19 at 02:23
  • 2
    aww thats rough. luckily im making an electron application, so i only need to worry about chromium and it works there :D great to know nonetheless!! – oldboy Oct 07 '19 at 02:26
2

For letters, \p{L} will match any Unicode character in the category "letter". Note that this is not well supported.

Source: https://stackoverflow.com/a/3010005

See also: https://www.regular-expressions.info/unicode.html

Skylar
  • 928
  • 5
  • 18