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.

Read Also:  jquery datatables ajax json example - Ajax source

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.

Read Also:  JavaScript Redirect URL Example

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Pagination in PHP and MySQLi Source Code
  2. Read Also:  How to add custom jquery image validation?
  3. Read Also:  Ckeditor required field validation using Jquery
  4. Read Also:  JQuery Push Key And Value Into An Array
  5. Read Also:  jquery AJAX Dynamically Add remove PHP MySQLi
  6. Read Also:  jquery remove last comma from Array Example
  7. Read Also:  Laravel 5.7 Jquery Ajax CRUD(insert update delete)
  8. Read Also:  Display Uploaded Image Using Javascript Example
  9. Read Also:  jquery datatables ajax json example - Ajax source
  10. Read Also:  Ckeditor required field validation using Jquery