Regex - isBinaryValue() method - returns information if given value is a binary value

This commit is contained in:
Meritoo
2018-01-10 17:35:42 +01:00
parent 780d4df17e
commit e9b8fb8852
2 changed files with 85 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ class Regex
'money' => '/^[-+]?\d+([\.,]{1}\d*)?$/',
'color' => '/^[a-f0-9]{6}$/i',
'bundleName' => '/^(([A-Z]{1}[a-z0-9]+)((?2))*)(Bundle)$/',
'binaryValue' => '/[^\x20-\x7E\t\r\n]/',
];
/**
@@ -796,4 +797,21 @@ class Regex
return (bool)preg_match_all($pattern, $htmlAttributes);
}
/**
* Returns information if given value is a binary value
*
* @param string $value Value to verify
* @return bool
*/
public static function isBinaryValue($value)
{
if (!is_string($value)) {
return false;
}
$pattern = self::$patterns['binaryValue'];
return (bool)preg_match($pattern, $value);
}
}