mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Regex - isValidHtmlAttribute() & areValidHtmlAttributes() methods - returns information if given html attribute is valid & if given html attributes are valid
This commit is contained in:
@@ -32,6 +32,7 @@ class Regex
|
||||
'urlDomain' => '([\da-z\.-]+)\.([a-z\.]{2,6})(\/)?([\w\.\-]*)?(\?)?([\w \.\-\/=&]*)\/?$/i',
|
||||
'letterOrDigit' => '/[a-zA-Z0-9]+/',
|
||||
'htmlEntity' => '/&[a-z0-9]+;/',
|
||||
'htmlAttribute' => '/([\w-]+)="([\w -]+)"/',
|
||||
'fileName' => '/.+\.\w+$/',
|
||||
'isQuoted' => '/^[\'"]{1}.+[\'"]{1}$/',
|
||||
'windowsBasedPath' => '/^[A-Z]{1}:\\\.*$/',
|
||||
@@ -751,4 +752,48 @@ class Regex
|
||||
{
|
||||
return self::$patterns['bundleName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pattern used to validate / verify html attribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlAttributePattern()
|
||||
{
|
||||
return self::$patterns['htmlAttribute'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if given html attribute is valid
|
||||
*
|
||||
* @param string $htmlAttribute The html attribute to verify
|
||||
* @return bool
|
||||
*/
|
||||
public static function isValidHtmlAttribute($htmlAttribute)
|
||||
{
|
||||
if (!is_string($htmlAttribute)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pattern = self::getHtmlAttributePattern();
|
||||
|
||||
return (bool)preg_match($pattern, $htmlAttribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if given html attributes are valid
|
||||
*
|
||||
* @param string $htmlAttributes The html attributes to verify
|
||||
* @return bool
|
||||
*/
|
||||
public static function areValidHtmlAttributes($htmlAttributes)
|
||||
{
|
||||
if (!is_string($htmlAttributes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pattern = self::getHtmlAttributePattern();
|
||||
|
||||
return (bool)preg_match_all($pattern, $htmlAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user