remove non alphanumeric characters javascript

Today, We want to share with you remove non alphanumeric characters javascript.In this post we will show you remove numbers from string javascript, hear for Javascript – extract letters from an alphanumerical string via loop we will give you demo and example for implement.In this post, we will learn about PHP preg_match – only allow alphanumeric strings and – _ characters
with an example.

javascript replace non alphanumeric except spaces

Remove not alphanumeric characters from string

Removing non-alphanumeric chars

input.replace(/\W/g, '')

string.replace(/[^A-Za-z0-9]/g, '');


var userStr = '123abcABC-_*([email protected]#$%^&*()_-={}[]:\"<>,.?/~`';
var stripped = userStr.replace(/[^A-Za-z0-9]/g, '');

Regex to remove all non alpha-numeric and replace spaces with +

userStr = userStr.replace(/[^a-z0-9+]+/gi, '+');


userStr = userStr.replace(/\(.+?\)/g, '');


input.replace(/\W/g, '') //doesnt include underscores


input.replace(/[^0-9a-z]/gi, '') //removes/deletes underscores too

JavaScript Form Validation: Remove Non Alphanumeric Chars

<!DOCTYPE html>
  <title>Remove Non Alphanumeric Chars -</title>
  var userStr = "(123)-//[45Awr%6][email protected]%&k";
  var regex = /\W/g;
  var resultStr = userStr.replace(regex, " ");
  document.write("The Original String was : " + userStr);
  document.write("<br>The replaced String : " + resultStr);

I hope you get an idea about remove non alphanumeric characters javascript.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.