User Guide

Table Of Contents
Validating form fields 667
Validating form fields
This section describes basic validation of form fields. Later sections in this chapter describe other
validation types and techniques that you can use, including regular expression validation,
masking, hidden field validation, JavaScript validation, and validation using CFML tags and
functions.
In basic form field validation, you do the following:
Use a cfinput or cftextarea tag.
Specify a validation type, such as numeric, or multiple types.
Optionally, specify an error message.
Optionally, specify a validation technique. (By default, ColdFusion uses onSubmit validation.)
The following example specifies onBlur validation of a telephone number:
Phone: <cfinput type="text" name="HPhone"
validateat="onBlur"
validate="required,telephone"
message="Please enter a standard U.S. telephone number with an optional
extension, such as x12345">
The following sections describe considerations for validation in cfinput and cftextarea tags,
and show a more complete example.
Validation type considerations
General considerations Consider the following issues when you determine how to validate
form data:
When you validate form data using onBlur, onSubmit, onServer, or hidden form field
validation, you can specify one or more validation types for each field that you validate. For
example, you can specify that a field entry is required and that it must be numeric. To specify
multiple validation types for onSubmit, onBlur, or onServer validation, specify the type values
in a comma-delimited list.
If you use onBlur, onSubmit, or onServer type validation, you can specify only one error
message for each field that you validate. If you use hidden field validation, you can create a
custom message for each validation rule (with the exception of range checking).
In the cfinput tag, most validation type attributes apply only to text or password fields.
Validation algorithm differences The underlying validation code used when validating form
data can differ depending on the validation technique and the form type. As a result, the
algorithms used vary in some instances, including the following:
The validation algorithms used for date/time values in onSubmit and OnBlur validation are
different from those used for all server-side validation techniques.
The algorithms used for onSubmit and OnBlur validation in Flash might vary from those used
for HTML or XML format, and generally follow simpler rules.
For detailed information on the validation algorithms used for validation techniques used on the
server, see Validating form data using hidden fields” on page 675.