In this tutorial, we will discuss about jquery remove special characters from string. I would like to share with you how to remove special characters from a string in jquery.In article goes in detailed on how to replace special character in string. you will easily learn how to remove all special charcters from a string in jquery.
I will give some simple step 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.let start and run below html file.
Example:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
</html>
jQuery code:
$(document).ready(function(){
string = "Hi, Web$%#StuffSolution@@@";
stringNew = string.replace(/[^\w\s]/gi, '');
console.log(stringNew);
});
Output:
Hi WebStuffSolution
I hope this tutorial help you.