Extend text validation to accept multiple inputs
This commit is contained in:
@@ -17,11 +17,16 @@ class SihnonFramework_Validation_Text extends SihnonFramework_Validation {
|
|||||||
static::Whitespace => ':space:',
|
static::Whitespace => ':space:',
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function charset($input, $charset = static::Defaults) {
|
public static function charset($inputs, $charset = static::Defaults) {
|
||||||
static::pattern($input, static::buildCharsetPattern($charset));
|
static::pattern($inputs, static::buildCharsetPattern($charset));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function length($input, $min_length = null, $max_length = null) {
|
public static function length($inputs, $min_length = null, $max_length = null) {
|
||||||
|
if ( ! is_array($inputs)) {
|
||||||
|
$inputs = array($inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($inputs as $input) {
|
||||||
$length = strlen($input);
|
$length = strlen($input);
|
||||||
|
|
||||||
if ($min_length !== null && $length < $min_length) {
|
if ($min_length !== null && $length < $min_length) {
|
||||||
@@ -32,12 +37,19 @@ class SihnonFramework_Validation_Text extends SihnonFramework_Validation {
|
|||||||
throw new SihnonFramework_Exception_InvalidLength();
|
throw new SihnonFramework_Exception_InvalidLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function pattern($input, $pattern) {
|
public static function pattern($inputs, $pattern) {
|
||||||
|
if ( ! is_array($inputs)) {
|
||||||
|
$inputs = array($inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($inputs as $input) {
|
||||||
if ( ! preg_match($pattern, $input)) {
|
if ( ! preg_match($pattern, $input)) {
|
||||||
throw new SihnonFramework_Exception_InvalidContent();
|
throw new SihnonFramework_Exception_InvalidContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static function buildCharsetPattern($charset) {
|
protected static function buildCharsetPattern($charset) {
|
||||||
$classes = '';
|
$classes = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user