0

I am trying to check text with regular expression and i need to check if it contains only letters, spaces and also non english characters.

I have this one:

var check = /^[a-zA-Z_0-9][a-zA-Z_0-9\s]*$/g.test(input.value);

It works fine but if input.value contains "ã" or "é" it gives false.

I googled and find that you can use unicode filter like this:

/\p{L}/u

I tryed to combine but with no results.

How can i solve this?

Thank you all.

shrivallabha.redij
  • 5,832
  • 1
  • 12
  • 27
Peter Pan
  • 55
  • 8
  • `\p{L}` and similar constructs are only supported in new environments, you might just add those characters you want to permit to the character sets for better compatibility – CertainPerformance Apr 24 '19 at 10:26
  • @CertainPerformance thank you for your answer. I would like to try your tip but i'm not good with regex. How do i add the characters? Thank you very much. – Peter Pan Apr 24 '19 at 10:28
  • You mean something like `^\p{L}[\p{L}\s]*$`? – Sweeper Apr 24 '19 at 10:30
  • What do you define as "*non english characters*"? Does it include Cyrillic? Chinese? Korean? Mathematical notations? Arabic? – VLAZ Apr 24 '19 at 10:31
  • @Sweeper thank you but is not working :/ – Peter Pan Apr 24 '19 at 10:39
  • @VLAZ for now it would be just portuguese, but yes it would be nice to accept letters from other lang but just letters and numbers. Thank you. – Peter Pan Apr 24 '19 at 10:42
  • Possible duplicate of [Regular expression to match non-English characters?](https://stackoverflow.com/questions/150033/regular-expression-to-match-non-english-characters) – VLAZ Apr 24 '19 at 10:46

1 Answers1

1

The following will include extended latin characters:

var check = /^[a-zA-Z_0-9\u00C0-\u017F][a-zA-Z_0-9\u00C0-\u017F\s]*$/g.test(input.value);

See https://en.wikipedia.org/wiki/Latin_script_in_Unicode for more information.

Phil
  • 274
  • 2
  • 5