
By validating user input you can not only enforce business rules, but also improve application security, preventing invalid or even harmful data from being sent to the server. For example, a validator can ensure that a Social Security Number contains nine digits or is in the format NNN-NN-NNNN. Flex provides a set of built-in validators for many types of input data, including e-mail addresses, phone numbers, and ZIP codes, to list a few.
In addition, with some relatively simple ActionScript, you can extend the Flex Validator class to meet specialized needs. Thus, you can validate any Flex form field against custom business rules without relying on server-side code.
This article shows how to create a custom validator and use it in a Flex Form container. In the process, it demonstrates the power of ActionScript subclasses.
Note: You can import this archive using Import > Flex Builder > Flex Project.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
Alex Cougarman is a Web application developer at UNC-TV in Research Triangle Park, North Carolina. Alex holds a bachelor of science in computer science from UNC Wilmington, where he worked as an applications programmer and analyst. Visit Alex's blog.