For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Validating Data-Developing guide / 

Validating form fields

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

In basic form field validation, 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 information describes 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 (except for 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 validation algorithms used for all server-side validation techniques.
  • The algorithms used for onSubmit and OnBlur validation in Flash can vary from those algorithms 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.

Validating data in XML skinnable forms

If you create an XML skinnable form and use any skin provided by Adobe, such as the basic.xsl or silver.xsl skin, you can use all form validation techniques that are available for HTML forms. 
If you use a custom skin (XSL file), the available validation techniques depend on the skin. The cf_webroot\CFIDE\scripts\xsl directory contains a _cfformvalidation.xsl file that implements all ColdFusion HTML form validation techniques and supports onBlur, onSubmit, onServer, and hidden form field validation. XML skin writers can include this file in their skin XSLT to implement ColdFusion validation for their skin.

Example: basic form validation

The following form asks for information to use when registering a new user. It checks to make sure that the user enters required information. (Only the telephone number is optional.) It also checks to make sure that the telephone number and e-mail address are properly formatted and that the number to use in a challenge question is in the proper range. This example performs onSubmit validation. It posts back to itself, and dumps the submitted results.

<cfif IsDefined("form.fieldnames")>
<cfdump var="#form#"><br>
</cfif>

<cfform name="myform" preservedata="Yes" >
First Name: <cfinput type="text" size="15" name="firstname"
required="yes" message="You must enter a first name."><br>
Last Name: <cfinput type="text" size="25" name="lastname"
required="yes" message="You must enter a last name."><br>
Telephone: <cfinput type="text" size="20" name="telephone"
validate="telephone" message="You must enter your telephone
number, for example 617-555-1212 x1234"><br>
E-mail: <cfinput type="text" size="25" name="email"
validate="email" required="Yes"
message="You must enter a valid e-mail address."><br>
Password: <cfinput type="password" size="12" name="password1"
required="yes" maxlength="12"
message="You must enter a password."><br>
Reenter password: <cfinput type="password" size="12" name="password2"
required="yes" maxlength="12"
message="You must enter your password twice."><br>
We will ask you for the following number, in the range 100-999 if you forget
your password.<br>
Number: <cfinput type="text" size="5" name="chalenge"
validate="range" range="100,999" required="Yes"
message="You must enter a reminder number in the range 100-999."><br>
<cfinput type="submit" name="submitit">
</cfform>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices