Files
spa-api/system/validation/rules/format_of.php

43 lines
801 B
PHP
Raw Normal View History

2011-06-21 20:11:17 -05:00
<?php namespace System\Validation\Rules;
use System\Validation\Nullable_Rule;
2011-06-21 20:11:17 -05:00
class Format_Of extends Nullable_Rule {
2011-06-21 20:11:17 -05:00
/**
* The regular expression that will be used to validate the attribute.
2011-06-21 20:11:17 -05:00
*
* @var string
*/
public $expression;
/**
* Evaluate the validity of an attribute.
*
* @param string $attribute
* @param array $attributes
* @return bool
2011-06-21 20:11:17 -05:00
*/
public function check($attribute, $attributes)
{
if ( ! is_null($nullable = parent::check($attribute, $attributes)))
2011-06-21 20:11:17 -05:00
{
return $nullable;
2011-06-21 20:11:17 -05:00
}
return preg_match($this->expression, $attributes[$attribute]);
}
/**
* Set the regular expression.
*
* @param string $expression
2011-06-21 20:11:17 -05:00
* @return Format_Of
*/
2011-06-21 22:22:52 -05:00
public function using($expression)
2011-06-21 20:11:17 -05:00
{
$this->expression = $expression;
return $this;
}
}