Using Regular Expression to Replace Special Characters from String

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 1265
Write below code:-
<script type = "text/javascript">
function ReplaceCharacters()
{
var str = document.getElementById('txt_comments').value;
//It will replace all characters except alphabets, characters. and space
alert(str.replace(/[^a-zA-Z0-9-. ]/g, ""));
}
</script>

Comments or Responses

Login to post response