Mega Code Archive

 
Categories / Flex / Data Model
 

Using RegExpValidator to find all the matches on the pattern

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">     <mx:Script>                  import mx.events.ValidationResultEvent;         import mx.validators.RegExpValidationResult;         import mx.controls.Alert;         private function handleValidation(event:ValidationResultEvent):void         {             var oneResult:RegExpValidationResult;             for (var i:int = 0; i < event.results.length; i++)             {                 oneResult = event.results[i];                 Alert.show("matched Index:" + oneResult.matchedIndex +                            "\nmatched string:" + oneResult.matchedString                            ,"RegEx Results",Alert.NONMODAL);             }         }            </mx:Script>     <mx:RegExpValidator source="{test}"                          property="text"                          flags="gmi"                          valid="handleValidation(event)"                          expression="m[ai]n"                         noMatchError="I don't like it!"                          trigger="{submitButton}"                         triggerEvent="click" />     <mx:Text text="Try me:" />     <mx:TextInput id="test" />     <mx:Button label="Submit" id="submitButton" /> </mx:Application>