Can someone provide a regular expression to search and replace illegal characters found
Example, removing �
I am not sure how many types of 'illegal' characters exist but I think this will be a good start.
Many thanks
edit - I have no control over the data, we're trying to create a catch for the potentially bad data we're receiving.
Using a replace() method with a regular expression To remove a character from a string, use string replace() and regular expression. This combination is used to remove all occurrences of the particular character, unlike the previous function. A regular expression is used instead of a string along with global property.
var nospecial=/^[^* | \ " : < > [ ] { } ` \ ( ) '' ; @ & $]+$/; if(address. match(nospecial)){ alert('Special characters like * | \ " : < > [ ] { } ` \ ( ) \'\' ; @ & $ are not allowed'); return false; but it is not working.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With