User Guide

Validating Data Types 91
If the variable is not in a valid date format, an error occurs and the page stops
processing.
Validating form field data types
One limitation of standard HTML forms is that you cannot validate that users input
the type or range of data you expect. ColdFusion enables you to do several types of
data validation by adding hidden fields to forms.
The following table describes the hidden field suffixes that you can use to do
validation:
Note
Adding a validation rule to a field does not make it a required field. You need to add a
separate _required hidden field if you want to ensure user entry.
The following procedure creates a simple form for entering a start date and a salary.
It uses hidden fields to ensure that you enter data and that the data is in the right
format.
This example illustrates another concept that might seem surprising. You can use
the same CFML page as both a form page and its action page. Because the only
action is to display the values of the two variables that you enter, the action is on the
same page as the form.
Field Suffix Value Attribute Description
_integer
Custom error
message
Verifies that the user entered a number. If the
user enters a floating point value, it is rounded to
an integer.
_float
Custom error
message
Verifies that the user entered a number. Does not
do any rounding of floating point values.
_range
MIN=MinValue
MAX=MaxValue
Verifies that the numeric value entered is within
the specified boundaries. You can specify one or
both of the boundaries separated by a space.
_date
Custom error
message
Verifies that the user entered a date and converts
the date into the proper ODBC date format. Will
accept most common date forms; for example,
9/1/98; Sept. 9, 1998.
_time
Custom error
message
Verifies that the user correctly entered a time and
converts the time to the proper ODBC time
format.
_eurodate
Custom error
message
Verifies that the user entered a date in a standard
European date format and converts into the
proper ODBC date format.