Skip to main content

Posts

Showing posts with the label Regular Expression to Replace Special Characters from String using JavaScript

Regular Expression to Replace Special Characters from String using JavaScript

Hello everyone, I am going share the code sample for how to Replace Special Charactersfrom String   like you can see the below image. In the above output image, you can see, when I clicked on " Remove Special Characters " button to display an alert text-box input text are not showing the special characters in the result string but I putting the some special charters in the in the text-box, you can see, edit and click on below given plunker link. For live demo go to http://embed.plnkr.co/06dJ3A/preview The JavaScript code with regular expression for Replacing Special Characters from String  as give below function removeSpecialCharacters() {     var regExpr = /[^a-zA-Z0-9-. ]/g ;     var userText = document.getElementById( 'user' ).value;     alert(userText.replace(regExpr, "" )); } The Full Live demo code as given below < !DOCTYPE html > < html ...