validatesLengthOf()
Description
Validates that the value of the specified property matches the length requirements supplied. Use the exactly, maximum, minimum and within arguments to specify the length requirements.
Function Syntax
validatesLengthOf([ properties, message, when, allowBlank, exactly, maximum, minimum, within, 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). |
message |
string |
No | [property] is the wrong length |
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. |
exactly |
numeric |
No | 0 |
The exact length that the property value has to be. |
maximum |
numeric |
No | 0 |
The maximum length that the property value has to be. |
minimum |
numeric |
No | 0 |
The minimum length that the property value has to be. |
within |
string |
No | |
A list of two values (minimum and maximum) that the length of the property value has to fall within. |
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 `firstname` and `lastName` properties are not more than 50 characters and use square brackets to dynamically insert the property name when the error message is displayed to the user (the `firstName` property will be displayed as "first name") --->
<cfset validatesLengthOf(properties="firstName,lastName", maximum=50, message="Please shorten your [property] please, 50 characters is the maximum length allowed.")>
<!--- Make sure that the `password` property is between 4 and 15 characters --->
<cfset validatesLengthOf(property="password", within="4,20", message="The password length has to be between 4 and 20 characters.")>
