The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

removing special characters

how do i remove all the illegal characters with regular expression in javascript? how should the regex look like? i am not very good with regex.

i am trying to do like str.replace('\([\w][\d])*\g', '');
i was thinking if i could do a condition in regex where i could say if the character is not alphanumeric, i will replace it with an empty char. but i have no idea how to do that.

i am trying to have the string which may contains illegal characters into the url. i am not encoding the characters into html entities because i am worry it may affect the SEO and make the url looks long and ugly as well.

the other issue is that i have another input box where i do not allow users to enter special characters. all special characters would want to be automatically stripped off on submit.

oh...no...i mean why through the way you have done, where put the regex to look for numbers and letters could end up removing the special characters?
it looks really clever but i thought it looks more like replacing the numebers and letters instead of the opposite.

did u mean the ^ is the character that make the regex to do the opposite?