Geoff,
Try:
public var validIPExpression:RegExp =
/^(([01]?[0-9]\{1,2\}|2[0-4][0-9]|25[0-5])\.)\{3\}([01]?[0-9]\{1,2\}|2[0-4][0-9]|25[0-5])$/;
instead.
Could be because by directly specifying the expression, the MXML->AS
parser correctly decides to treat it as a RegExp. But when directly
binding to the value, binding sees it just as a String.
HTH,
Ian
On Thu, Aug 13, 2009 at 5:17 PM, Geoffrey<[email protected]> wrote:
>
>
> We use the code-behind technique to attach AS to MXML. Doing this has caused
> an interesting issue with RegExpValidator. If the regular expression is
> defined in the AS file and contains a quantifier, it causes validation to
> act funky.
>
> In the following example, if you type about 20 zeroes into the IP field it
> goes from invalid, to valid, and back to invalid. Obviously it should be
> invalid after the first zero is typed and stay that way unless a proper IP
> is entered. However, if you take the same regExp string and put it in the
> MXML file it works as expected. Note that escaping or not escaping the { or
> } characters while the string is in the AS file has no effect on the
> validation.
>
> Test.mxml
> ---------
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> xmlns:local="*"
> minWidth="800" minHeight="600">
>
> <local:MyComp/>
>
> </mx:Application>
>
> MyComp.mxml
> -----------
> <?xml version="1.0" encoding="utf-8"?>
> <custom:MyCompScript xmlns:mx="http://www.adobe.com/2006/mxml"
> xmlns:custom="*">
>
> <mx:FormItem id="fiIPAddress"
> label="IP Address: "
> required="true">
> <mx:TextInput id="tiIPAddress"/>
> </mx:FormItem>
>
> <mx:RegExpValidator id="ipValidator"
> expression="{validIPExpression}"
> source="{tiIPAddress}"
> property="text"
> trigger="{tiIPAddress}"
> triggerEvent="change"
> noMatchError="Invalid IP Address Format."/>
>
> <!-- works if you use
> expression="^(([01]?[0-9]\{1,2\}|2[0-4][0-9]|25[0-5])\.)\{3\}([01]?[0-9]\{1,2\}|2[0-4][0-9]|25[0-5])$"-->
>
> </custom:MyCompScript>
>
> MyCompScript.as
> ---------------
> package
> {
> import mx.containers.Form;
>
> public class MyCompScript extends Form
> {
> [Bindable]
> public var validIPExpression:String =
> "^(([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.){3}([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])$";
> //public var validIPExpression:String =
> "^(([01]?[0-9]\{1,2\}|2[0-4][0-9]|25[0-5])\.)\{3\}([01]?[0-9]\{1,2\}|2[0-4][0-9]|25[0-5])$";
> // Neither of the above work
>
> public function MyCompScript()
> {
> super();
> }
> }
> }
>
> Does this seem like a bug, or just a limitation introduced by using the
> code-behind technique?
>
> Thanks,
> Geoff
>
> p.s. Don't know what code-behind is?
> http://learn.adobe.com/wiki/display/Flex/Code+Behind
>
>