1

I'm trying to validate this regular expression with JavaScript. What I need it to do is check if at least 2 words are entered. By words I mean strings with any characters except some specific. Everything is good until I end a string with a special unicode character, such as "ā". Then the expression fails to validate. Currently the expression looks like this - /^([^<>\\\/\?&{};#{}\+\*()"=%@,:0-9]{1,}\w){2,}$/i

Any ideas on how to validate unicode expressions in this case?

Deez
  • 849
  • 2
  • 9
  • 28
  • 1
    [XRegExp](http://xregexp.com/)? – R. Martinho Fernandes Apr 22 '13 at 14:33
  • See [Regular expression to match non-english characters?](http://stackoverflow.com/questions/150033/regular-expression-to-match-non-english-characters), particularly the comments to the accepted answer. And BTW, you have two `{}` in your character class. And what are you considering to be a valid word separator? – MikeM Apr 22 '13 at 15:03
  • See my answer to [this question](http://stackoverflow.com/a/7578937/626273) – stema Apr 22 '13 at 15:17
  • `/^([^<>\\\/\?&{};#\+\*()"=%@,:0-9\s]+(\s+|$)){2,}$/i` <- try that? You're matching white space with your character class, I think you want to avoid that. Also: I think you're using `\w` as a whitespace matcher, but that is not what it does. `\w` matches `[A-Za-z0-9_]`, so I switched it to `(\s+|$)` (whitespace or end of string). – FrankieTheKneeMan Apr 22 '13 at 16:47
  • Thanks, the expression posted above seems to be working nicely. – Deez Apr 23 '13 at 10:37

1 Answers1

0

On most programming lang, you would try this Unicode Regex:

/^([^<>\\\/\?&{};#{}\+\*()"=%@,:0-9\s]{1,}\p{L}){2,}$/ims

Or like this

/^([^\P]{1,}\p{L}){2,}$/ims

However, JS doesnt support Unicode that easily :(

See here for example: Javascript + Unicode regexes

Community
  • 1
  • 1
Raheel Hasan
  • 5,753
  • 4
  • 39
  • 70