Back
validatesLengthOf()
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.
1. Ensure that `firstName` and `lastName` are no more than 50 characters
validatesLengthOf(
properties="firstName,lastName",
maximum=50,
message="Please shorten your [property] please (50 characters max)."
);
2. Ensure `password` is between 4 and 20 characters
validatesLengthOf(
property="password",
within="4,20",
message="The password length must be between 4 and 20 characters."
);
3. Ensure `username` is exactly 8 characters
validatesLengthOf(
property="username",
exactly=8,
message="Username must be exactly 8 characters."
);
4. Only validate if `region` is 'US'
validatesLengthOf(
property="zipCode",
exactly=5,
condition="this.region eq 'US'",
message="US zip codes must be exactly 5 digits."
);
5. Skip validation if property is blank
validatesLengthOf(
property="nickname",
maximum=15,
allowBlank=true
);
Copied!