You are viewing documentation for v1.0.x. Change

validatesFormatOf()

Description

Validates that the value of the specified property is formatted correctly by matching it against a regular expression using the regEx argument and/or against a built-in CFML validation type (creditcard, date, email etc) using the type argument.

Function Syntax

validatesFormatOf([ properties, regEx, type, message, when, allowBlank, if, unless ])

Parameters

Parameter Type Required Default Description
properties string No Name of property or list of property names to validate against (can also be called with the property argument).
regEx string No Regular expression to verify against.
type string No One of the following types to verify against: creditcard, date, email, eurodate, guid, social_security_number, ssn, telephone, time, URL, USdate, UUID, zipcode (will be passed through to CFML's isValid function).
message string No [property] is invalid Supply a custom error message here to override the built-in one.
when string No onSave Pass in onCreate or onUpdate to limit when this validation occurs (by default validation will occur on both create and update, i.e. onSave).
allowBlank boolean No false If set to true, validation will be skipped if the property value is an empty string or doesn't exist at all.
if string No String expression to be evaluated that decides if validation will be run (if the expression returns true validation will run).
unless string No String expression to be evaluated that decides if validation will be run (if the expression returns false validation will run).

Examples

<!--- Make sure that the user has entered a correct credit card --->
<cfset validatesFormatOf(property="cc", type="creditcard")>

<!--- Make sure that the user has entered an email address ending with the `.se` domain when the `ipCheck` methods returns `true` and it's not Sunday, also supply a custom error message that overrides the Wheels default one --->
<cfset validatesFormatOf(property="email", regEx="^.*@.*\.se$", if="ipCheck()", unless="DayOfWeek() IS 1" message="Sorry, you must have a Swedish email address to use this website")>