删除JavaScript中的无效字符 [英] Removing invalid characters in JavaScript
本文介绍了删除JavaScript中的无效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以提供正则表达式来搜索和替换发现的非法字符
Can someone provide a regular expression to search and replace illegal characters found
示例,删除
我不确定存在多少种非法"字符,但我认为这将是一个好的开始.
I am not sure how many types of 'illegal' characters exist but I think this will be a good start.
非常感谢
编辑-我无法控制数据,我们正试图为接收到的潜在不良数据创建陷阱.
edit - I have no control over the data, we're trying to create a catch for the potentially bad data we're receiving.
推荐答案
无效字符在解析时会转换为0xFFFD,因此所有无效字符代码都将替换为:
Invalid characters get converted to 0xFFFD on parsing, so any invalid character codes would get replaced with:
myString = myString.replace(/\uFFFD/g, '')
You can get all types of invalid sorts of chars here
这篇关于删除JavaScript中的无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文