box-o-sand/flex-practice/03f1-custom-components/com/mycustom/components/TextInputEmail.as

36 lines
990 B
ActionScript
Raw Normal View History

2010-02-23 02:49:18 +00:00
package com.mycustom.components
{
import mx.controls.TextInput;
import mx.events.ValidationResultEvent;
import mx.validators.EmailValidator;
import flash.events.Event;
import mx.validators.ValidationResult;
public class TextInputEmail extends TextInput
{
private var emailValidator:EmailValidator = new EmailValidator();
private var validator:ValidationResultEvent;
public function TextInputEmail()
{
super();
this.emailValidator.source = this;
this.emailValidator.property = "text";
this.addEventListener("enter", this.validate);
}
private function validate(event:Event):void
{
validator = emailValidator.validate();
if (validator.type == ValidationResultEvent.VALID)
{
this.errorString = "";
} else {
this.errorString = validator.message;
}
}
}
}