I want to allow unicode characters like chinese chars etc but don't want to allow special chars like *,[,],~ and also space, enter etc.
Asked
Active
Viewed 743 times
0
-
2How do I ask a good question? http://stackoverflow.com/help/how-to-ask – Youcef LAIDANI Jun 28 '16 at 08:06
-
1Possible duplicate of [Javascript + Unicode regexes](http://stackoverflow.com/questions/280712/javascript-unicode-regexes) – Maria Ivanova Jun 28 '16 at 08:22
-
Also possible duplicate of [javascript-unicode-string-chinese-character-but-no-punctuation](http://stackoverflow.com/questions/21109011/javascript-unicode-string-chinese-character-but-no-punctuation) – Maria Ivanova Jun 28 '16 at 08:30
-
@YoucefLaidani note you can link to that page typing `[ask]`. – fedorqui Jun 28 '16 at 08:33
-
Thank you @fedoriqui this is a new information – Youcef LAIDANI Jun 28 '16 at 08:40
1 Answers
-1
Metacharacter \W
finds a non word character which includes all special characters.
var str = "{,[]&$pop^%$%%}";
var patt = /\W/g;
var string = str.replace(patt,"");
window.alert(string);

Batman25663
- 272
- 1
- 3
- 12
-
"\w or \W only matches ASCII based characters" - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Regular_expression_and_Unicode_characters – Kivi Shapiro Mar 10 '17 at 19:43