Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Russ Hammett
Russ Hammett

Posted on • Originally published atkritner.blogspot.com on

     

Flex Email address validation component

I was attempting to find a decent email validation component for flex - one with validators built in and all the bells and whistles. I wasn't able to find one at a quick glance, so I put this guy together, and it seems to actually be working so far :O

\<?xml version="1.0" encoding="utf-8"?\>\<!-- Created By: Russ Hammett Create Date: 2012-01-03 Description: Text input that validates an email address. use "required" to control if the email address is required. access the public variable isValidEmail to determine if validation passed on the email address Modified By: Russ Hammett Modify Date: 2012-01-06 Modify Desc: Updated validateEmail function to be public and update errorString accordingly when validation fails or passes.--\>\<mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml" maxChars="50"  creationComplete="onCreationCompleted();" focusOut="validateEmail();" \> \<mx:Script\> \<![CDATA[ import mx.events.ValidationResultEvent; private var \_isValidEmail:Boolean = true; public function set isValidEmail(value:Boolean):void { \_isValidEmail = value;  } [Bindable] public function get isValidEmail():Boolean { return \_isValidEmail; }  [Bindable] public var required:Boolean = false; /\*\* \* On Creation Completed \* \*/ private function onCreationCompleted():void { if (required) { emailValidator.enabled = true; } else { emailValidator.enabled = false;  } } /\*\* \* Validate Email \* \*/ public function validateEmail():void { var vldEmail:ValidationResultEvent; if (this.length \> 0) { emailValidator.enabled = true; vldEmail = emailValidator.validate(this.text); if (vldEmail.type == ValidationResultEvent.VALID) { isValidEmail = true; this.errorString = ''; } else { isValidEmail = false; this.errorString = vldEmail.message; } } else { emailValidator.enabled = false; if (required) { emailValidator.enabled = true; vldEmail = emailValidator.validate(this.text); isValidEmail = false; this.errorString = vldEmail.message; } else { isValidEmail = true; this.errorString = ''; } } } ]]\> \</mx:Script\> \<mx:EmailValidator   source="{this}" property="text" required="{required}" requiredFieldError="Email Field is Required." invalidCharError="Invalid characters in your email address."  invalidDomainError= "The domain in your email address is incorrectly formatted."  invalidIPDomainError="The IP domain in your email address is incorrectly formatted."  invalidPeriodsInDomainError="The domain in your email address has consecutive periods."  missingAtSignError="Missing an at character in your email address."  missingPeriodInDomainError="The domain in your email address is missing a period."  missingUsernameError="The username in your email address is missing."  tooManyAtSignsError="Too many at characters in your email address." /\> \</mx:TextInput\>

Thankshttp://www.bloggersentral.com/2009/04/how-to-show-code-in-blog-post.html#free for teaching me how to paste code (and making it look pretty) in blogger..

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Dad, programmer, faux-chef, gamer, book reader
  • Location
    Westminster, MD
  • Education
    BS Computer Studies
  • Work
    Software Engineer at Huntington Ingalls Industries (Formerly G2 Inc.)
  • Joined

More fromRuss Hammett

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp