Saturday, August 30, 2008

Replace special charecters with '-' in the given string using JavaScript


 <script language="JavaScript">
    var temp1;
    var temp = new String('Thi\'s is a te!!!!s$t st>ri9ng... S"o??? What#...');
    document.write(temp + '<br>');
    temp =  temp.replace(/[^a-zA-Z 0-9]+/g,'-');
    document.write(temp + '<br>');
    temp1=temp.replace(/\s/g,'-');
    document.write(temp1 + '<br>');
    </script>
--
ఇట్లు మీ,
చంద్రశేఖర్.

No comments: