I have to validate a textfield in AS3 if there are chars like # $ % @ ~ | {} [] / \ etc. i.e find unnecessary chars and remove them from the textfield.
I use a search AS3 function which works with regular expressions, but I am not good at RegEx so can anyone help me with this? I would like a regular expression so that a search function searches the characters above and if it finds any of them then returns true.
The following snippet removes the blacklisted characters you have defined (not recommended):
Option 1: Character class with blacklist.
But there are a LOT of other control, punctuation and Unicode characters that you probably also want to avoid (e.g.
[¥®^«±µ¼½¾]etc.. Instead, it is most likely better to define which chars you wish to allow, and then remove all characters that are NOT the ones to be allowed.Option 2: Negated character class with whitelist.
Lets say you want to allow all latin letters, numbers, spaces, dots, dashes, underscores and colons (i.e.
[A-Za-z0-9 .\-_:]). Here is a snippet that will remove all character that are not in the whitelist: