I've a开发者_StackOverflow中文版 free text field on my form where the users can type in anything. Some users are pasting text into this field from Word documents with some weird characters that I don't want to go in my DB. (e.g. webding font characters) I'm trying to get a regular expression that would give me only the alphanum and the punctuation characters. But when I try the following, the output is still all the characters. How can I leave them out?
<html><body><script type="text/javascript">var str="";document.write(str.replace(/[^a-zA-Z 0-9 [:punct]]+/g, " "));</script></body></html>
If you want only ascii, use /[^ -~]+/
as regex. The problem is your [:punct:]
statement. Perhaps javascript does not support [:punct:]
?
精彩评论