O'Reilly logo

Flex 4 Cookbook by Garth Braithwaite, Joshua Noble, Todd Anderson, Marco Casario, Rich Tretola

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14. 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 strings into a certain format if specific patterns are or are not encountered, and returning error messages to users if necessary properties are not encountered. That is, all three are useful for dealing with the sorts of data that we need from third parties or users that may not always be supplied in the format required by our applications—things like phone numbers, capitalized names, currencies, zip codes, and ISBN numbers. 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 or RegExp object introduced in ActionScript 3. This is 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 the length of a field. Validation can be implemented simply by setting the source property of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required