Alan K Holden


Negative Number Restrict Attribute via ActionScript

When you set the "restrict" attribute of a Flex component (like a TextInput) within MXML markup, and you'd like to allow negative numbers (the hyphen); the process is pretty straightforward:

<s:TextInput id="myTI" width="100" restrict=".0-9-" />

But if you're making this assignment dynamically (you only allow negative numbers under some circumstance), the hyphen will not survive during an ActionScript passage like this:

myTI.restrict = '0-9.-';

You'll need to escape the hyphen, and escape the slash that escapes the hyphen as well:

myTI.restrict = '0-9.\\-';


Full Version