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$%#SolutionStuff@@@";
newString = myString.replace(/[^\w\s]/gi, '');
console.log(newString);
});
</script>
</html>
Output:
Hi, ItSolutionStuff
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Download File using JQuery?
- How to Remove Last Element from Array in JQuery?
- How to Remove First Element from Array in JQuery?
- How to Check Atleast One Checkbox is Checked or Not in JQuery?
- How to Add JQuery Modal Popup in PHP?
- How to Check Image Loaded or Not in JQuery?
- How to Check If Element is Exists or Not in jQuery?
- Display Loading Image when AJAX Call is in Progress Example
- Check and Uncheck All Checkbox using JQuery Example
- How to Allow Only One Checkbox Checked at a Time in JQuery?
- How to Convert Line Breaks to br in jQuery ?
- How to Check Object is Empty or Not in JQuery?