How to remove control characters from string?

Control characters in Unicode are at codepoints U+0000 through U+001F and U+007F through U+009F. Use a RegExp to find those control characters and replace them with an empty string:

str.replace(/[\u0000-\u001F\u007F-\u009F]/g, "")

If you want to remove additional characters, add the characters to the character class inside the RegExp. For example, to remove U+200B ZERO WIDTH SPACE as well, add \u200B before the ].

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)