0

I want to allow unicode characters like chinese chars etc but don't want to allow special chars like *,[,],~ and also space, enter etc.

Nilay Shah
  • 31
  • 5

1 Answers1

-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