Removing invalid characters in JavaScript

后端 未结 3 827
一个人的身影
一个人的身影 2020-12-29 05:30

Can someone provide a regular expression to search and replace illegal characters found

Example, removing �

I am not sure how many types of \'illegal\' char

3条回答
  •  礼貌的吻别
    2020-12-29 06:02

    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

提交回复
热议问题