1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| <?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/29/validating-email-addresses-using-the-emailvalidator-class-in-flex/ -->
<mx:Application name="EmailValidator_validate_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
initialize="init();">
<mx:Style>
@font-face {
src: local("Verdana");
fontFamily: VerdanaEmbedded;
fontWeight: bold;
}
.errorMessage {
fontFamily: VerdanaEmbedded;
fontWeight: bold;
}
.validTextInputStyle {
backgroundAlpha: 0.6;
backgroundColor: haloGreen;
}
.invalidTextInputStyle {
backgroundAlpha: 0.3;
backgroundColor: red;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.validators.EmailValidator;
import mx.controls.Alert;
import mx.events.ValidationResultEvent;
private var emailValidator:EmailValidator;
private function init():void {
emailValidator = new EmailValidator();
emailValidator.source = textInput;
emailValidator.property = "text";
emailValidator.trigger = btn;
emailValidator.triggerEvent = MouseEvent.CLICK;
emailValidator.addEventListener(ValidationResultEvent.VALID, emailValidator_valid);
emailValidator.addEventListener(ValidationResultEvent.INVALID, emailValidator_invalid);
}
private function emailValidator_valid(evt:ValidationResultEvent):void {
textInput.errorString = "";
textInput.styleName = "validTextInputStyle";
Alert.show(textInput.text, "You entered a valid email address:");
}
private function emailValidator_invalid(evt:ValidationResultEvent):void {
textInput.errorString = evt.message;
textInput.styleName = "invalidTextInputStyle";
message.visible = true;
message.text = evt.message;
message.visible = false;
}
]]>
</mx:Script>
<mx:Fade id="dissolveEffect"
startDelay="1500"
alphaFrom="1.0"
alphaTo="0.0" />
<mx:Form defaultButton="{btn}">
<mx:FormItem label="email address:"
direction="horizontal">
<mx:TextInput id="textInput"
focusAlpha="0.5" />
<mx:Button id="btn"
label="validate" />
</mx:FormItem>
</mx:Form>
<mx:Label id="message"
styleName="errorMessage"
hideEffect="{dissolveEffect}" />
</mx:Application> |
Partager