Data Validation

One of the big benefits of using CFFORM over standard HTML forms is the built-in data validation that is available. Both the CFINPUT and CFTEXTINPUT tags have an attribute called VALIDATE that accepts any of the following values:

CreditCard

Validates the form field data using the mod10 algorithm. Credit-card numbers can be entered as a single number or with dashes or spaces. ColdFusion automatically strips dashes and spaces before validating.

Date

Requires the form-field value to be in the U.S. date format mm/dd/yyyy.

EuroDate

Requires the form-field value to be in the European date format dd/mm/yyyy.

Float

Requires the form-field value to be a floating-point number.

Integer

Requires the form-field value to be an integer.

Social_Security_Number

Requires the form-field value to be a U.S. social security number in the format xxx-xx-xxxx or xxx xx xxxx.

Telephone

Requires the form-field value to be a U.S. telephone number formatted either xxx-xxx-xxxx or xxx xxx xxxx. The area code and exchange are required to begin with a number in the range of 1-9.

Time

Requires that the form-field value be entered as a valid time using the format hh:mm:ss.

ZipCode

Requires that the form-field value be entered as either a five- or nine-digit U.S. ZIP code using the format xxxxx, xxxxx-xxxx, or xxxxx xxxx.

In addition to the VALIDATE attribute, the CFINPUT and CFTEXTINPUT tags as well as the CFGRID, CFSLIDER, and CFTREE tags support an additional attribute for ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.