Chapter 15. Validating and Formatting Data

When working with data, you’ll frequently need to ensure that the data adheres to certain rules. When the data is from user input, this is called validation. When the data is being displayed or needs to be in a particular form before storing it or sending it to a service method, this is called formatting. The Flex framework provides mechanisms for both of these types of operations. In this chapter, we will look at both validating and formatting data.

Validating User Input

When you work with user input, you frequently may want to validate that input before submitting it for some sort of course of action, either client-side or server-side. For example, if you want to submit form data to a server script that inserts the data to a database, you may need to verify that the values are in the correct format so that you can insert them (e.g., a numeric value needs to be a number and a date needs to be formatted in a way that your script can parse it into the format you require for the database). Often it is advisable to add both client-side and server-side validation. The server-side validation ensures that no strange or incorrect values were inserted at the time the request was made, and the client-side validation makes sure the data is valid before even making a request. Only client-side validation is within the scope of Flex coding, and therefore we will look at how to validate data client-side using Flex.

You can write your own validation procedures ...

Get Programming Flex 3 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.