diff --git a/CHANGELOG.md b/CHANGELOG.md index 09121fc..104390e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ This update accompanies the release of the [Telegram Bot API 6.7](https://core.t to `\TgBotLib\Objects\Telegram\InlineKeyboardButton` * Added methods `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup::removeRow` & `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup::addRow` to `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup` * Added method `\TgBotLib\Objects\Telegram\WebAppInfo::setUrl` to `\TgBotLib\Objects\Telegram\WebAppInfo` + * Added methods `\TgBotLib\Classes\Validate::url`, `\TgBotLib\Classes\Validate::length`, & `\TgBotLib\Classes\Validate::isHttps` to `\TgBotLib\Classes\Validate` ## [6.6.0] - 2023-04-10 diff --git a/src/TgBotLib/Classes/Validate.php b/src/TgBotLib/Classes/Validate.php index 1af67e9..0793c9d 100644 --- a/src/TgBotLib/Classes/Validate.php +++ b/src/TgBotLib/Classes/Validate.php @@ -4,5 +4,40 @@ class Validate { + /** + * Validates if a URL is valid or not + * + * @param string $url + * @return bool + */ + public static function url(string $url): bool + { + return filter_var($url, FILTER_VALIDATE_URL) !== false; + } + /** + * Returns true if the given input is within the specified length range + * + * @param string $input + * @param int $min_length + * @param int $max_length + * @return bool + */ + public static function length(string $input, int $min_length, int $max_length): bool + { + $length = strlen($input); + + return $length >= $min_length && $length <= $max_length; + } + + /** + * Determines if the given URL is an HTTPS URL + * + * @param string $url + * @return bool + */ + public static function isHttps(string $url): bool + { + return strpos($url, 'https://') === 0; + } } \ No newline at end of file