Categories
Uncategorized

Validating CSS values with regex in PHP

Experimental!

/**
 * Regex validation of CSS values for the options.
 *
 * @param $subject
 *
 * @return bool
 */
private function css_value_validation( $subject ) {
	$pattern = '(([0-9]{1,})(\.{0,1})([0-9]{0,})(px|pt|pc|em|ex|ch|rem|vh|vw|vmin|vmax|%{0,1})(\s{0,1})){1,4}';
	if ( preg_match( $pattern, $subject ) ) {
		return true;
	}

	return false;
}