Write a Regular Expression to remove all special characters from a JavaScript String?

JavascriptWeb DevelopmentFront End Technology

To remove all special characters from a JavaScript string, you can try to run the following code −

Example

<html>
   <head>
      <script>
         var str = "@!Welcome to our website$$";
         document.write(str);
         
         // Removing Special Characters
         document.write("<br>"+str.replace(/[^\w\s]/gi, ''));
      </script>
   </head>
   
   <body>
   </body>
</html>
raja
Published on 23-Feb-2018 11:16:30
Advertisements