Daemonite: Flex Custom Validator: Australian Tax File Number (TFN) Archive

Daemonite: Flex Custom Validator: Australian Tax File Number (TFN) Archive


Tuesday, July 19, 2005
Flex Custom Validator: Australian Tax File Number (TFN)

One of Flex's little joys is the great client-side validation options you have. We've put together an example of extending the Flex mx.validators.Validator class to validate the Australian Tax File Number. It should be a good example to get you going on any sort of custom validation.

The better your data input validation throughout your system, the higher the quality of your data. 'Client side' or 'Server side' validation? is the next question. Oh and security is another important issue.

TFN Validation

Flexs mx.validators package with mx.validators.Validator as its super class deals with those sorts of issues. Already built in and ready to use are the following validation classes:

  • CreditCardValidator
  • CurrencyValidator
  • DateValidator
  • EmailValidator
  • NumberValidator
  • PhoneNumberValidator
  • SocialSecurityValidator
  • StringValidator
  • ZipCodeValidator

But how do we write our own validation class tailored to our specific needs?

Download file

  1. downloade 'tfn_validation.zip'
  2. place the 2 files 'TFNValidation.mxml' and 'TFNValidator.as' under the same directory on your Flex server
  3. execute 'TFNValidation.mxml'

Worth mentioning:

TFNValidator.as:

  • always extend 'yourValidator.as' from 'mx.validators.Validator'
  • always write a constructor for your AS classes, even if its empty.
  • write a 'doValidation(....)' method which calls your
  • static function 'validateXXX' method
  • have a read on the comments in 'TFNValidator.as'

TFNValidator.mxml:

  • note the relationship: 'myTaxFileNumber' <-> 'tfnModel' <-> 'TFNValidator'
  • mx.validators.Validator.isStructureValid(this,'tfnModel') initiates a validation of all fields in the tfnModel. Of course you can apply different Validators to different model fields.
  • last but not least 'ErrorTip { borderColor: #000066; color: #FFFFFF }' will give your error message the right style and thats what it is all about ....

Flex validation is powerful and easyly extendable to your specific application needs. As it all is performed client sided and not easyly viewable by users is is one of the best validation processes available for web applications these days.

Josef

Posted by josef at 10:50 AM | Permalink
Trackback: http://blog.daemon.com.au/cgi-bin/dmblog/mt-tb.cgi/287

Comments