开发者

Regex: How to leave out webding font characters?

开发者 https://www.devze.com 2022-12-29 13:39 出处:网络
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

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:]?

0

精彩评论

暂无评论...
验证码 换一张
取 消