Using RegExpValidator to find all the matches on the pattern : RegExpValidator « Data Model « Flex






Using RegExpValidator to find all the matches on the pattern

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>

   
    
  








Related examples in the same category

1.RegExpValidator matches text against a RegEx patternRegExpValidator matches text against a RegEx pattern
2.Use regular expression ABC\d to match a pattern consisting of the letters A, B, and C in sequence followed by any digitUse regular expression ABC\d to match a pattern consisting of the letters A, B, and C in sequence followed by any digit