User Guide

Table Of Contents
660 Chapter 28: Validating Data
ColdFusion provides several techniques to ensure that data is valid. These include techniques for
validating form data and for validating ColdFusion variables. They also include techniques for
validating form data before the user submits it to ColdFusion, or on the ColdFusion server.
When you design data validation you consider the following factors:
The validation technique Whether to validate on the client’s browser or on the server, and the
specific server- or client-side validation technique, such as whether to validate when a field loses
focus or when the user submits the form.
The validation type The specific method that you use to validate the data, including the rules
that you apply to test the data validity, such as testing for a valid telephone number.
The following sections describe the ColdFusion MX validation techniques and provide
information on selecting a technique that is appropriate for your application. They also describe
the validation types that ColdFusion MX supports. Later sections describe particular techniques
in detail.
Validation techniques
Different validation techniques apply to different ColdFusion tags or coding environments; for
example, you can use masking only in HTML and Macromedia Flash format
cfinput tags.
Validation techniques also vary in where and when they execute; for example, on the client
browser when the user submits form data, or on the server when processing data.
The following table describes the ColdFusion MX validation techniques:
Validation
technique
Applies to Where and when
performed
Description
mask
(
mask
attribute)
HTML and
Flash format
cfinput tags
On the client as the
user enters data
ColdFusion MX generates JavaScript or
ActionScript to directly control the data a user
enters by specifying a pattern. For example,
999-999-9999 requires a user to enter ten
digits, and automatically fills in the dash (-)
separators to create a formatted telephone
number.
For detailed information on using masks, see
“Handling invalid data” on page 669.
onBlur
(
validateat=
"onBlur"
attribute)
cfinput and
cftextarea tags
On the client when
the data field loses
focus
In HTML and XML format, ColdFusion MX
generates JavaScript that runs on the
browser to check whether entered data is
valid and provide immediate feedback, if the
entry is invalid.
In Flash format, uses Flash built-in validation
routines.