Add class for validating color codes
This commit is contained in:
parent
9d4d326d6a
commit
89e06769f1
|
@ -85,6 +85,27 @@ final class MD_STD_IN {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* String sanitization for 3 o4 6 characters RGB color codes (sans the leading #).
|
||||
*
|
||||
* @param mixed $input Input string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitize_rgb_color($input):string {
|
||||
|
||||
$output = \filter_var($input,
|
||||
FILTER_SANITIZE_STRING,
|
||||
FILTER_FLAG_NO_ENCODE_QUOTES);
|
||||
|
||||
if (!(preg_match('/^[a-zA-Z0-9]{3}$/', $output)) && !(preg_match('/^[a-zA-Z0-9]{6}$/', $output))) {
|
||||
throw new MDInvalidColorCode("Invalid color code provided: " . $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves HTTP input texts from GET or POST variables, whatever is provided.
|
||||
* If neither is given, returns a provided default.
|
||||
|
|
Loading…
Reference in New Issue
Block a user