Exactly, haykelbj. What I need help with is rewriting the regular expression for the isCurrency test so that the strings "true,$" or "true, $" will return true in AS3. I'm not so hot at writing regexps... isCurrency returns true on those two strings in JavaScript; I don't know why they return false in AS3.
--- In [email protected], "haykelbj" <[EMAIL PROTECTED]> wrote: > > The JavaScript and ActionScript codes are not doing exactly the same > thing. In your AS code, at a certain point you are doing the following > assignment: > _testValue = qualifier.toLowerCase()+ ",$"; > This will result in _testValue = "true,$" which will make the test > isCurrency.test(_testValue) return false which is right because > isCurrency's regex is /^, ?\$/. > > > --- In [email protected], "jwebbsuccess" <jwebb@> wrote: > > > > I have a regular expression that works in JavaScript and does not work > > in ActionScript 3, even though both languages supposedly use the > > ECMAScript standard for regular expressions. I need the expression to > > return true when ever it tests the two strings below: > > > > true,$ > > true, $ > > > > I need the expression to return false whenever the string is not the > > same as one of the two above. > > > > I've attached the HTML that demonstrates that the regular expressions > > work in JavaScript. Can you modify the same expressions in the Flex > > code, provided below, to produce the same result? > > > > Thanks. > > > > --------------------------------------------------------------- > > <html> > > <head> > > <style type="text/css"> > > #doc {background-color:#EFEFEF;text-align:center;} > > #testBlock > > > {background-color:#FFFFFF;text-align:left;width:600px;height:500px;margin: > > 0 auto;border:1px solid #FF9900;padding:0 20px;} > > .regexp {color:#FF0000;} > > .testval {color:#00CC00;} > > </style> > > </head> > > <body id="doc"> > > <div id="testBlock"> > > <h1 id="test1"></h1> > > <h1 id="test2"></h1> > > <h1 id="testValue"></h1> > > <p>The only two true values should be "true,$" and "true, $"; > > everything else should be false.</p> > > <script type="text/javascript"> > > > > //TEST YOUR REGULAR EXPRESSIONS HERE. > > var re1 = /^true\b(.*)$/; > > var re2 = /^, ?\$/; > > var str = "true,$"; > > > > //THE VALUES USED IN YOUR TESTS WILL APPEAR IN THE PAGE... > > document.getElementById( "test1" ).innerHTML = "Regular > > Expression > > 1: <span class='regexp'>" + re1 + "</span>"; > > document.getElementById( "test2" ).innerHTML = "Regular > > Expression > > 1: <span class='regexp'>" + re2 + "</span>"; > > document.getElementById( "testValue" ).innerHTML = "Test > > Value: > > <span class='testval'>" + str + "</span>"; > > > > if ( ( resultArray = re1.exec( str ) ) != null ) > > { > > alert( "Test 1 successful" ); > > if ( re2.test( resultArray[ 1 ] ) ) > > { > > alert( "Test 2 successful" ); > > } > > else > > { > > alert( "Test 2 failed" ); > > } > > } > > </script> > > </div> > > </body> > > </html> > > > > --------------------------------------------------------------- > > > > <?xml version="1.0"?> > > <!-- wrapper/GetURLInfo.mxml --> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > creationComplete="runRegExpTest( event )"> > > <mx:Script> > > <![CDATA[ > > import mx.events.FlexEvent; > > import mx.controls.Alert; > > > > [Bindable] private var _test1:String = ""; > > [Bindable] private var _test2:String = ""; > > [Bindable] private var _testValue:String = ""; > > > > private function runRegExpTest( e:FlexEvent ):void > > { > > var isTrue:RegExp =/^true\b(.*)$/; > > var isCurrency:RegExp =/^, ?\$/; > > var qualifier:String = "TRUE"; > > _test1 = isTrue.toString(); > > _test2 = isCurrency.toString(); > > var msg1:String; > > var msg2:String; > > > > if ( isTrue.test( qualifier.toLowerCase() ) ) > > { > > _testValue = qualifier.toLowerCase()+ ",$"; > > msg1 = "The qualifier is: " + qualifier.toLowerCase() + ", > > the test value is ( " + _testValue + " ) and returns: " + > > isCurrency.test( _testValue ).toString(); > > trace( msg1 ); > > Alert.show( msg1 ); > > if ( isCurrency.test( _testValue ) ) > > { > > msg2 = "The test is SUCCESSFUL!"; > > trace( msg2 ); > > Alert.show( msg2 ); > > } > > else > > { > > msg2 = "The 'isCurrency' RegExp is UNSUCCESSFUL"; > > trace( msg2 ); > > Alert.show( msg2 ); > > } > > } > > } > > ]]> > > </mx:Script> > > <mx:Form color="#FCFCFC" cornerRadius="10" borderStyle="outset" > > backgroundColor="#FAF7F7"> > > <mx:FormItem label="'isTrue' regular expression test:" > > fontSize="18" color="#000000"> > > <mx:Label text="{ _test1 }" fontSize="18" color="#BF5100" > > fontWeight="bold"/> > > </mx:FormItem> > > <mx:FormItem label="'isCurrency' regular expression test:" > > fontSize="18" color="#000000"> > > <mx:Label text="{ _test2 }" fontSize="18" color="#BF5100" > > fontWeight="bold"/> > > </mx:FormItem> > > <mx:FormItem label="'test value is: " fontSize="18" > color="#000000"> > > <mx:Label text="{ _testValue }" fontSize="18" > > color="#BF5100" fontWeight="bold"/> > > </mx:FormItem> > > </mx:Form> > > </mx:Application> > > >

