User Guide

Table Of Contents
670 Chapter 28: Validating Data
For cfparam and cfargument tags, you use standard ColdFusion MX error-handling
techniques. You can include the tag in a
try block and use a catch block to handle the error,
or you can use a custom error-handling page. The following example form action page code
uses a custom error page, expresserr.cfm, to handle the error that the
cfparam tag generates if a
user submits a form with an invalid e-mail address:
<cferror type="EXCEPTION" exception="expression" template="expresserr.cfm">
<cfif IsDefined("form.fieldnames")>
<cfparam name="form.custEmail" type="email">
<!--- Normal form processing code goes here. --->
</cfif>
Masking form input values
The cfinput tag mask attribute controls the format of data that can be entered into a text or
datefield input field. You can also use a mask attribute in the cfcalendar tag. You can
combine masking and validation on a field.
In HTML and Flash form format, a mask can control the format of data entered into a text
field.
In the cfcalendar tag, and, for Flash format forms, the datefield type cfinput field, a
mask can control the format of the date that ColdFusion MX uses for the date a user chooses
in the displayed calendar.
Note: The standard ColdFusion MX XML skins do not support masking.
Masking text input
In text fields, ColdFusion automatically inserts literal mask characters, such as - characters in
telephone numbers. Users type only the variable part of the field. You can use the following
characters to mask data:
The following pattern enforces entry of a part number of the format EB-1234-c1-098765, where
the user starts the entry by typing the first numeric character, such as 1. ColdFusion fills in the
preceding EB prefix and all hyphen (-) characters. The user must enter four numbers, followed by
two alphanumeric characters, followed by six numbers.
<cfinput type="text" name="newPart" mask="EB-9999-XX-999999" />
Note: You cannot force a user to type an A, X, 9, or question mark (?) character. To ensure that a
pattern is all-uppercase or all-lowercase, use the ColdFusion MX UCase or LCase functions in the
action page.
Mask character Effect
A Allows an uppercase or lowercase character: A–Z and a–z.
X Allows an uppercase or lowercase character or number: A–Z, a–z, and 0–9.
9 Allows a number: 0–9.
? Allows any character.
All other characters Automatically inserts the literal character.