Validating data using ActionScript 3.0
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="doValidate()">
<mx:Script>
import mx.validators.*;
private var phoneV:PhoneNumberValidator;
private function doValidate():void
{
phoneV = new PhoneNumberValidator();
phoneV.source = phoneTxt;
phoneV.property = "text";
phoneV.required = true;
phoneV.allowedFormatChars = "+,-";
phoneV.allowedFormatChars = "+-";
phoneV.invalidCharError = "Invalid char.";
phoneV.wrongLengthError = "Invalid format";
phoneV.requiredFieldError = "required";
phoneV.trigger = phoneTxt;
phoneV.triggerEvent = "change";
}
</mx:Script>
<mx:Form id="myForm">
<mx:FormHeading label="Insert Data" />
<mx:FormItem label="Insert Name" required="true">
<mx:TextInput id="nameTxt" />
</mx:FormItem>
<mx:FormItem label="Insert Surname">
<mx:TextInput id="surnameTxt" />
</mx:FormItem>
<mx:FormItem label="Insert Phone Number">
<mx:TextInput id="phoneTxt" />
</mx:FormItem>
</mx:Form>
</mx:Application>
Related examples in the same category