Header Ad

Saturday, August 30, 2008

JAVASCRIPT REGULAR EXPRESSION FOR REMOVING SPECIAL SYMBOLS

The following example will give the you the notes to replace the special characters in a string.

Place the following coed with in the script tags.

var temp1;

var temp = new String('Thi\'s is a te!!!!s$t st>ri9ng... S"o??? What#...');

document.write(temp + '
');

temp = temp.replace(/[^a-zA-Z 0-9]+/g,'-');

document.write(temp + '
');

temp1=temp.replace(/\s/g,'-');

document.write(temp1 + '
');