Adobe COLDFUSION 9 Manual page 36

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
• max: Maximum value if the validate is integer/numeric/
• minLength: Minimum length of the string if the validate is string
• maxLength: Maximum length of the string if the validate is string
• pattern: regex expression if the validator specified in validate attribute is regex
For example, the following code sets the validators for e-mail, zipcode, and age of an employee.
Note: For age,
checks if the value is an integer and
validate
<!---Setting validators for an employee's e-mail, age, and zipcode--->
<cfcomponent>
<cfproperty name="mail" validate="email">
<cfproperty name="zip" validate="zipcode">
<cfproperty name="age" validate="integer" validateparams="{min=18,max=60}"> </cfcomponent>
User-defined functions
You can write your own functions, user-defined functions (UDFs). You can use these functions in ColdFusion
expressions or in CFScript. You can call a user-defined function anywhere you can use a built-in CFML function. You
create UDFs using the
cffunction
tag can include ColdFusion tags and functions. UDFs that you create in CFScript can only include
cffunction
functions. You can create stand-alone UDFs or encapsulate them in a ColdFusion component.
User-defined functions let you encapsulate logic and operations that you use frequently in a single unit. This way, you
can write the code once and use it multiple times. UDFs ensure consistency of coding and enable you to structure your
CFML more efficiently.
Typical user-defined functions include mathematical routines, such as a function to calculate the logarithm of a
number; string manipulation routines, such as a function to convert a numeric monetary value to a string such as "two
dollars and three cents"; and can even include encryption and decryption routines.
Note: The Common Function Library Project at
functions.
For more information on user-defined functions, see
ColdFusion components
ColdFusion components encapsulate multiple, related, functions. A ColdFusion component is essentially a set of
related user-defined functions and variables, with additional functionality to provide and control access to the
component contents. ColdFusion components can make their data private, so that it is available to all functions (also
called methods) in the component, but not to any application that uses the component.
ColdFusion components have the following features:
• They are designed to provide related services in a single unit.
• They can provide web services and make them available over the Internet.
• They can provide ColdFusion services that Flash clients can call directly.
• They have several features that are familiar to object-oriented programmers, including data hiding, inheritance,
packages, and introspection.
For more information on ColdFusion components, see
validateparams
tag or the
cfscriptfunction
www.cflib.org
includes a number of free libraries of user-defined
"Writing and Calling User-Defined
"Building and Using ColdFusion
Last updated 8/5/2010
checks the range of the value supplied.
statement. UDFs that you create using the
Functions" on page 153.
Components" on page 177.
31

Advertisement

Table of Contents
loading

Table of Contents