Use regular expression ABC\d to match a pattern consisting of the letters A, B, and C in sequence followed by any digit
<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".
This user guide is licensed for use under the terms of the Creative Commons Attribution
Non-Commercial 3.0 License.
This License allows users to copy, distribute, and transmit the user guide for noncommercial
purposes only so long as
(1) proper attribution to Adobe is given as the owner of the user guide; and
(2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms.
The best way to provide notice is to include the following link.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
-->
<!-- validators\RegExpExample.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
import mx.events.ValidationResultEvent;
import mx.validators.*;
private function handleResult(event:ValidationResultEvent):void {
if (event.type == "valid")
{
// For valid events, the results Array contains
// RegExpValidationResult objects.
var xResult:RegExpValidationResult;
myTA.text="";
for (var i:uint = 0; i < event.results.length; i++)
{
xResult = event.results[i];
myTA.text=myTA.text + xResult.matchedIndex + " " +
xResult.matchedString + "\n";
}
}else{
// Not necessary, but if you needed to access it,
// the results array contains ValidationResult objects.
var result:ValidationResult;
myTA.text="";
}
}
</fx:Script>
<fx:Declarations>
<mx:RegExpValidator id="regExpV" source="{exp}"
property="text" flags="g" expression="{source.text}" valid="handleResult(event);"
invalid="handleResult(event);" />
</fx:Declarations>
<mx:Form>
<mx:FormItem label="Search string">
<s:TextInput id="exp" />
</mx:FormItem>
<mx:FormItem label="Regular expression">
<s:TextInput id="source" text="ABC\d" />
</mx:FormItem>
<mx:FormItem label="Results">
<s:TextArea id="myTA" />
</mx:FormItem>
</mx:Form>
</s:Application>
Related examples in the same category