Thanks for posting your solution. By the way, I also was able to get
my regex to work from ActionScript by storing as a String and
similarly escaping the curly braces with a backslash. The expression
attribute on mx:RegExpValidator is expecting a String, so attempting
to store in ActionScript as RegExp type did not work for me.
So, I think the following should work for you (untested):
public var expression: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])$;
and then
mx:RegExpValidator expression={expression} /
Jon
On Mon, Aug 31, 2009 at 4:52 PM, gtb104gtb...@yahoo.com wrote:
The solution was to declare the regexp in the mxml, escaping the { and }
characters. Once I did that, it worked as expected.
mx:RegExpValidator id=ipValidator
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])$/
source={tiIPAddress}
property=text
trigger={tiIPAddress}
triggerEvent=change
noMatchError=Invalid IP Address Format./
Geoff
--- In flexcoders@yahoogroups.com, Geoffrey gtb...@... wrote:
Didn't seem to help.
I changed the String to a RegExp, escaped and didn't escape the {}
characters, and also tried with and without the [Bindable] metadata tag. As
long as the regular expression is in the actionscript file, it just doesn't
work properly. Actually, in this instance, nothing ever validates as a
valid IP address.
Geoff
--- In flexcoders@yahoogroups.com, Ian Thomas ian@ wrote:
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, Geoffreygtb104@ 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
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Alternative FAQ location:
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links