Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Annotations > StringLengthFieldValidator Annotation
#editReport()

This validator checks that a String field is of the right length. It assumes that the field is a String. If neither minLength nor maxLength is set, nothing will be done.

Usage

The annotation must be applied at method level.

Parameters

Parameter Required Default Notes
message yes   field error message
key no   i18n key from language specific properties file.
fieldName no    
shortCircuit no false If this validator should be used as shortCircuit.
type yes ValidatorType.FIELD Enum value from ValidatorType. Either FIELD or SIMPLE can be used here.
trim no true Boolean property. Determines whether the String is trimmed before performing the length check.
minLength no   Integer property. The minimum length the String must be.
maxLength no   Integer property. The maximum length the String can be.

If neither minLength nor maxLength is set, nothing will be done.

Examples

@StringLengthFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, trim = true, minLength = "5",  maxLength = "12")