Using ActionScript to validate Email : EmailValidator « Data Model « Flex






Using ActionScript to validate Email

Using ActionScript to validate Email
    

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        
        import mx.validators.EmailValidator;
        import mx.validators.StringValidator;
        import mx.controls.Alert;
        import mx.events.ValidationResultEvent;
        
        public var emailVal:EmailValidator = new EmailValidator();
        public var stringVal:StringValidator = new StringValidator();
        
        public function validateForm():void 
        {
            var valResult:ValidationResultEvent;
            stringVal.source = username;
            stringVal.property = "text";
            stringVal.minLength = 10;
        
            emailVal.source = email;
            emailVal.property = "text";
        
            valResult = emailVal.validate(); 
        
            if(valResult.type == "invalid"){
                Alert.show("Invalid Email");
            } 

            valResult = stringVal.validate(); 

            if(valResult.type == "invalid"){
                Alert.show("Invalid Username");
            }   
        }
      
    </mx:Script>
    <mx:Text text="Email:" />
    <mx:TextInput id="email" />
    <mx:Text text="Enter your username:" />
    <mx:TextInput id="username" />
    <mx:Button label="Submit" id="submitButton" click="validateForm()" />
</mx:Application>

   
    
    
    
  








Related examples in the same category

1.Email address validationEmail address validation
2.Using a submit button to validate form fieldsUsing a submit button to validate form fields
3.Use EmailValidator to validate email cell editorUse EmailValidator to validate email cell editor
4.Data source for EmailValidatorData source for EmailValidator
5.Using the EmailValidator classUsing the EmailValidator class
6.Using EmailValidatorUsing EmailValidator
7.Validate Email With ActionScriptValidate Email With ActionScript
8.Use new line character to error messageUse new line character to error message