User Guide
90 Chapter 6 Making Variables Dynamic
Validating Data Types
It is often not sufficient that input data merely exists; it must also have the right
format. For example, a date field must have data in a date format. A salary field must
have data in a numeric or currency format. There are many ways to ensure the
validity of data, including the following methods:
• Using the cfparam tag with the type attribute to validate any variable.
• Using a form
input tag with a hidden attribute to validate the contents of a form
input field.
• Using
cfform controls that have validation attributes. (For information on using
cfform tags, see Chapter 9, “Building Dynamic Forms” on page 135.)
• Using the cfqueryparam tag in a SQL WHERE clause to validate query
parameters.
Note
The data validation discussed in this chapter is done by the ColdFusion Server.
Validation using
cfform tags is done using JavaScript in the user’s browser, before
any data is sent to the server.
Using cfparam to validate the data type
The cfparam type attribute lets you validate the type of a parameter. You can specify
that the parameter type must be any of the following values:
For example, you can use the following code to validate the variable BirthDate:
<cfparam name="BirthDate" type="date">
Type value Meaning
any any value
array any array value
binary any binary value
boolean true, false, yes, or no
date any value in a valid date, time, or date-time format
numeric any number
query a query object
string a text string or single character
struct a structure
UUID a Universally Unique Identifier (UUID) formatted as
XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXX where X stands
for a hexadecimal digit (0-9 or A-F).
variableName a valid variable name