Chapter 15. Validation, Formatting, and Regular Expressions

Validation, formatting, and regular expressions may seem a somewhat strange grouping at first glance, but they tend to be used for similar things in the everyday experience of developers: parsing the format of strings to detect a certain pattern, altering the string into a certain format if specific patterns are or are not encountered, returning error messages to users if necessary properties are not encountered—things like phone numbers, capitalized first names, currency, zip codes, ISBN numbers, the sorts of data that we need from third parties or users that may not always be in the correct format required by our application. The Flex Framework provides two powerful tools to integrate this type of parsing and formatting with the UI elements of the Framework in the Validator and Formatter classes. Beneath both of these is the regular expression, a new introduction to the ActionScript language and Flash Player platform, but a venerable and powerful programming tool, used by nearly all, and loved and loathed in equal measure for its incredible power and difficult syntax.

The Validator is an event dispatcher object that checks a field within any Flex control to ensure that the value submitted falls within its set parameters. These parameters can indicate a certain format, whether a field is required, or a length of a field. The integration of the Validator with the Flex control means that displaying the result of a validation ...

Get Flex 3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.