1

The problem is that when I try to test it it returns always false. Do you have any idea why?

$('MyInput').mouseout(function () {
    alert($('MyInput').val()); // it is  "яяqqåå"
    alert(/^[\p{L}0-9\s\.\\\/\-]{2,20}$/.test($('MyInput').val()));
});
JotaBe
  • 38,030
  • 8
  • 98
  • 117
user2831001
  • 125
  • 1
  • 1
  • 9

1 Answers1

1

It is because Javascript regex doesn't support \p{L}

even this returns false:

/^\p{L}+/.test('a');

You can use this blanket unicode range to match your input text:

/^[\u0000-\uffff\d\s.\\\/-]{2,20}$/.test('яяqqåå');
//=> returns true
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Then how to include all letters from all languages? Because from what I saw \p{L} does that. p.s. I use in in C# valiadation – user2831001 Dec 17 '13 at 14:31
  • Above regex will definitely match cyrillic alphabets but you can also use `/^[\u0000-\u5500\d\s.\\\/-]{2,20}$/.test('яяqqåå');` for matching only cyrillic/english alphabets. – anubhava Dec 17 '13 at 14:44
  • i also need scandinavian and east-west europe – user2831001 Dec 17 '13 at 14:51
  • But this one allow me everything. I want to restrict symbols. – user2831001 Dec 17 '13 at 15:02
  • In Javascript you will have to use unicode ranges for each set. For example just to match `cyrillic ` you can use `[\u0400-\u5500]` range and this will return true: `/^[\u0400-\u5500\d\s.\\\/-]{2,20}$/.test('яя');` – anubhava Dec 17 '13 at 15:08