Maslosoft Mangan API
Class LengthValidatorAnnotation
StringValidator validates that the attribute value is of certain length.
Note, this validator should only be used with string-typed attributes.
In addition to the Maslosoft\Mangan\Annotations\Validators\ValidatorAnnotation::$message
property for setting a custom error message,
StringValidator has a couple custom error messages you can set that correspond to different
validation scenarios. For defining a custom message when the string is too short,
you may use the Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation::$tooShort
property. Similarly with Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation::$tooLong
. The messages may contain
placeholders that will be replaced with the actual content. In addition to the "{attribute}"
placeholder, recognized by all validators (see Validator), StringValidator allows for the following
placeholders to be specified:
- {min}: when using
Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation::$tooShort
, replaced with minimum length,Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation::$min
, if set. - {max}: when using
Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation::$tooLong
, replaced with the maximum length,Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation::$max
, if set. - {length}: when using
Maslosoft\Mangan\Annotations\Validators\ValidatorAnnotation::$message
, replaced with the exact required length,Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation::$is
, if set.
- Maslosoft\Addendum\Collections\MetaAnnotation
- Maslosoft\Mangan\Meta\ManganAnnotation
- Maslosoft\Mangan\Meta\ManganPropertyAnnotation
- Maslosoft\Mangan\Annotations\Validators\ValidatorAnnotation
- Maslosoft\Mangan\Annotations\Validators\LengthValidatorAnnotation uses Maslosoft\Mangan\Validators\Traits\AllowEmpty, Maslosoft\Mangan\Validators\Traits\When
Package: system\validators
Author: Qiang Xue qiang.xue@gmail.com
Version: $Id$
Since: 1.0
Located at Annotations/Validators/LengthValidatorAnnotation.php
Methods inherited from Maslosoft\Mangan\Meta\ManganPropertyAnnotation
Methods inherited from Maslosoft\Mangan\Meta\ManganAnnotation
Methods used from Maslosoft\Mangan\Validators\Traits\When
Constants summary
Constants inherited from Maslosoft\Mangan\Annotations\Validators\ValidatorAnnotation
Properties summary
public
integer
|
$max
maximum length. Defaults to null, meaning no maximum limit. |
#
null
|
public
integer
|
$min
minimum length. Defaults to null, meaning no minimum limit. |
#
null
|
public
integer
|
$is
exact length. Defaults to null, meaning no exact length limit. |
#
null
|
public
string
|
$tooShort
user-defined error message used when the value is too short. |
#
null
|
public
string
|
$tooLong
user-defined error message used when the value is too long. |
#
null
|
public
string
|
$msgInvalid
|
#
''
|
public
string
|
$msgTooShort
|
#
''
|
public
string
|
$msgTooLong
|
#
''
|
public
string
|
$msgLength
|
#
''
|
public
string
|
$encoding
the encoding of the string value to be validated (e.g. 'UTF-8'). This property is used only when mbstring PHP extension is enabled. The value of this property will be used as the 2nd parameter of the mb_strlen() function. If this property is not set, the application charset will be used. If this property is set false, then strlen() will be used even if mbstring is enabled. |
#
null
|
Properties inherited from Maslosoft\Mangan\Annotations\Validators\ValidatorAnnotation
$class
,
$except
,
$message
,
$on
,
$proxy
,
$safe
,
$skipOnError
,
$value