public function check()
{
if ($this->valueChanged && $this->readonly) {
return array('read_only', $this->printName());
}
if (null === $this->value || '' === $this->value) {
if ($this->required) {
return array('value_required', $this->printName());
}
} else {
// Expressions régulière
if ($this->regex) {
if (!preg_match('/' . $this->regex . '/mUsi', $this->value)) {
return array('bad_format', $this->printName());
}
}
// Longueur minimum et maximum
if ($this->minlength && strlen($this->value) < $this->minlength) {
return array('at_least', $this->printName(), $this->minlength);
}
if ($this->maxlength && strlen($this->value) > $this->maxlength) {
return array('not_more', $this->printName(), $this->maxlength);
}
}
// Contraintes custom
foreach ($this->constraints as $constraint) {
$err = $constraint($this->value);
if ($err) {
return $err;
}
}
}