00001 <?php
00002
00015
00016
00017
00018 import ('form.validation.FormValidator');
00019
00020 class FormValidatorLength extends FormValidator {
00021
00023 var $comparator;
00024
00026 var $length;
00027
00034 function FormValidatorLength(&$form, $field, $type, $message, $comparator, $length) {
00035 parent::FormValidator($form, $field, $type, $message);
00036 $this->comparator = $comparator;
00037 $this->length = $length;
00038 }
00039
00045 function isValid() {
00046 if ($this->isEmptyAndOptional()) {
00047 return true;
00048
00049 } else {
00050 $length = String::strlen(trim($this->form->getData($this->field)));
00051 switch ($this->comparator) {
00052 case '==':
00053 return $length == $this->length;
00054 case '!=':
00055 return $length != $this->length;
00056 case '<':
00057 return $length < $this->length;
00058 case '>':
00059 return $length > $this->length;
00060 case '<=':
00061 return $length <= $this->length;
00062 case '>=':
00063 return $length >= $this->length;
00064 }
00065 return false;
00066 }
00067 }
00068
00069 }
00070
00071 ?>