Set up validator for Form input fields : Form Validator « Components « Flex






Set up validator for Form input fields

Set up validator for Form input fields
     
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
   backgroundColor="#FFFFFF" width="550" height="300">
   
  <mx:Validator required="true" source="{fnametxt}" property="text" 
    trigger="{validatebtn}" triggerEvent="click" listener="{fnametxt}"/>
  <mx:Validator required="true" source="{lnametxt}" property="text"
    trigger="{validatebtn}" triggerEvent="click" listener="{lnametxt}"/>
  <mx:Validator required="true" source="{addresstxt}" property="text"
    trigger="{validatebtn}" triggerEvent="click" listener="{addresstxt}"/>
  <mx:Validator required="true" source="{citytxt}" property="text"
    trigger="{validatebtn}" triggerEvent="click" listener="{citytxt}"/>
  <mx:Validator required="true" source="{statetxt}" property="text"
    trigger="{validatebtn}" triggerEvent="click" listener="{statetxt}"/>  
  <mx:ZipCodeValidator required="true" source="{ziptxt}" property="text"
    trigger="{validatebtn}" triggerEvent="click" listener="{ziptxt}"/>
  <mx:EmailValidator source="{emailtxt}" property="text"
    trigger="{validatebtn}" triggerEvent="click" listener="{emailtxt}"/>
  <mx:PhoneNumberValidator source="{phonetxt}" property="text"
    trigger="{validatebtn}" triggerEvent="click" listener="{phonetxt}"/>
    
  <mx:Panel title="Contact Info" width="500" height="250">
  <mx:Form>
    <mx:FormItem label="Name" direction="horizontal">
      <mx:TextInput id="fnametxt" />
      <mx:TextInput id="lnametxt" />
    </mx:FormItem>
    <mx:FormItem label="Address">
      <mx:TextInput id="addresstxt"/>
    </mx:FormItem>
    <mx:FormItem label="City State, Zip" direction="horizontal">
      <mx:TextInput id="citytxt"/>
      <mx:TextInput id="statetxt" width="20"/>
      <mx:TextInput id="ziptxt" width="50"/>
    </mx:FormItem>
    <mx:FormItem label="Phone">
      <mx:TextInput id="phonetxt"/>
    </mx:FormItem>
    <mx:FormItem label="Email">
      <mx:TextInput id="emailtxt"/>
    </mx:FormItem>
    <mx:Button id="validatebtn" label="Validate"/>
  </mx:Form>
  </mx:Panel>
</mx:Application>

   
    
    
    
    
  








Related examples in the same category

1.Using Flex validators with form modelsUsing Flex validators with form models
2.Use Validator to validate data from a formUse Validator to validate data from a form
3.Validator, Model and Form controlsValidator, Model and Form controls
4.Using Validators.validateAll() method to validate a formUsing Validators.validateAll() method to validate a form
5.Validating form control contents data on user entryValidating form control contents data on user entry
6.Validate form data with ActionScriptValidate form data with ActionScript
7.Validating user input for form dataValidating user input for form data
8.Change form input box label when data is not validChange form input box label when data is not valid
9.Use ActionScript to validate form dataUse ActionScript to validate form data
10.Validate a date entered into a formValidate a date entered into a form
11.Validate an e-mail address to ensure that it is formatted correctlyValidate an e-mail address to ensure that it is formatted correctly