A few issues with your regex...
First, you need to escape many of those characters, as they have special meanings in regex. You can escape their special function (thereby referring only to the character) by preceding each with a backslash. Honestly, you can get away with escaping them all.
EDIT: \b does indeed mark a word boundary in most contexts, however, it is extraneous to our purposes here.
Your revised regex is...
private const my_regex:RegExp = /[\^\(\)\:\,\?\+\*\\\.]/g;
The other consideration is that, if you run my_regex.test(ti.text)
, if any of these characters appear in the string, it will return true. In order for your error string to have a value when there is a match, you have to reverse your logic. I did with the not (!
) operator before the call to .test
.
private function validateNow(evt:Event):void {
if (!my_regex.test(ti.text)) {
ti.errorString = null;
} else {
ti.errorString = "some error here";
}
}
I highly recommend having a reference on regular expressions handy. My personal favorite is The ActionScript 3.0 Bible 2e. Chapter 12 goes into exhaustive detail. If you prefer web resources, the AS3 documentation works nicely.