How to Remove Special Characters from a String in JQuery?

Hey Friends,

In this tute, we will discuss jquery remove special characters from string. I would like to share with you how to remove special characters from a string in jquery. you will learn how to remove all special characters from a string in jquery. This article goes in detailed on how to replace a special character in a string in jquery. Alright, let’s dive into the steps.

I will give you a very simple and short example of how to remove all special characters from string in jquery. we will use replace function to remove all special characters from text. so, let’s run the below html file.

Example:

index.html

<!DOCTYPE html>

<html>

<head>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

</head>

<body>

</body>

<script type="text/javascript">

$(document).ready(function () {

/* Remove Special Character from String in JQuery */

myString = "Hi, It$%#[email protected]@@";

newString = myString.replace(/[^ws]/gi, '');

console.log(newString);

});

</script>

</html>

Output:

Hi, ItSolutionStuff

I hope it can help you…

Leave a Comment