Validating With Regular Expressions - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

When you specify an input type in the
input type when you submit the form, and submits form data only on a successful match. A
successful form submission returns the value True and returns the value False if validation fails.

Validating with regular expressions

You can use regular expressions to match and validate the text that users enter in
tags. Ordinary characters are combined with special characters to define the match
cftextinput
pattern. The validation succeeds only if the user input matches the pattern.
Regular expressions allow you to check input text for a wide variety of conditions. For example, if
a date field must only contain dates between 1950 and 2050, you can create a regular expression
that matches only numbers in that range. You can concatenate simple regular expressions into
complex search criteria to validate against complex patterns, such as any of several words with
different endings.
You can use ColdFusion variables and functions in regular expressions. The ColdFusion server
evaluates the variables and functions before the regular expression is evaluated. For example, you
can validate against a value that you generate dynamically from other input data or database
values.
Note: The rules listed in this section are for JavaScript regular expressions, and apply to the regular
expressions used in cfinput and cftextinput tags only. These rules differ from those used by the
ColdFusion functions REFind, REReplace, REFindNoCase, and REReplaceNoCase. For information
on regular expressions used in ColdFusion functions, see
Functions," on page
Special characters
Because special characters are the operators in regular expressions, in order to represent a special
character as an ordinary one, you must precede it with a backslash. For example, use double
backslash characters (\\) to represent a backslash character.
Single-character regular expressions
The following rules govern regular expressions that match a single character:
Special characters are:
Any character that is not a special character or escaped by being preceded by the backslash (\)
matches itself.
A backslash (\) followed by any special character matches the literal character itself, that is, the
backslash escapes the special character.
A period (.) matches any character except newline.
A set of characters enclosed in brackets ([]) is a one-character regular expression that matches
any of the characters in that set. For example, "[akm]" matches an "a", "k", or "m". If you
include ] (closing square bracket) in square brackets, it must be the first character. Otherwise, it
does not work, even if you use \].
A dash can indicate a range of characters. For example, "[a-z]" matches any lowercase letter.
If the first character of a set of characters in bracket is the caret (^), the expression matches any
character except those in the set. It does not match the empty string. For example: [^akm]
matches any character except "a", "k", or "m". The caret loses its special meaning if it is not the
first character of the set.
610
Chapter 27: Building Dynamic Forms
validate
143.
+ * ? . [ ^ $ ( ) { | \
attribute, ColdFusion tests for the specified
Chapter 7, "Using Regular Expressions in
and
cfinput

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents