Index: trunk/extensions/Validator/includes/criteria/CriterionHasLength.php |
— | — | @@ -13,20 +13,31 @@ |
14 | 14 | */ |
15 | 15 | class CriterionHasLength extends ParameterCriterion { |
16 | 16 | |
| 17 | + protected $lowerBound; |
| 18 | + protected $upperBound; |
| 19 | + |
17 | 20 | /** |
18 | 21 | * Constructor. |
19 | 22 | * |
20 | 23 | * @since 0.4 |
21 | 24 | */ |
22 | | - public function __construct( ) { |
| 25 | + public function __construct( $lowerBound, $upperBound = false ) { |
23 | 26 | parent::__construct(); |
| 27 | + |
| 28 | + $this->lowerBound = $lowerBound; |
| 29 | + $this->upperBound = $upperBound === false ? $lowerBound : $upperBound; |
24 | 30 | } |
25 | 31 | |
26 | 32 | /** |
27 | 33 | * @see ParameterCriterion::validate |
28 | 34 | */ |
29 | 35 | public function validate( $value ) { |
| 36 | + $strlen = strlen( $value ); |
30 | 37 | |
| 38 | + if ( $strlen > $this->upperBound ) return false; |
| 39 | + if ( $strlen < $this->lowerBound ) return false; |
| 40 | + |
| 41 | + return true; |
31 | 42 | } |
32 | 43 | |
33 | 44 | } |
\ No newline at end of file |