610
Chapter 27: Building Dynamic Forms
When you specify an input type in the
validate
attribute, ColdFusion tests for the specified
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
cfinput
and
cftextinput
tags. Ordinary characters are combined with special characters to define the match
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
Chapter 7, “Using Regular Expressions in
Functions,” on page 143
.
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.
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...