openvk/Web/Util/Validator.php
Alexander Minkin 6ec54a379d
feat: add linting of code (#1220)
* feat(lint): add php-cs-fixer for linting

Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0.

This is not the reformatting commit.

* style: format code according to PER-CS 2.0 with php-cs-fixer

* ci(actions): add lint action

Resolves #1132.
2025-01-31 18:20:13 +03:00

40 lines
912 B
PHP

<?php
declare(strict_types=1);
namespace openvk\Web\Util;
use Chandler\Patterns\TSimpleSingleton;
class Validator
{
use TSimpleSingleton;
public function emailValid(string $email): bool
{
if (empty($email)) {
return false;
}
$email = trim($email);
[$user, $domain] = explode("@", $email);
if (is_null($domain)) {
return false;
}
if (iconv_strlen($user) > 64) {
return false;
}
$domain = idn_to_ascii($domain) . ".";
return checkdnsrr($domain, "MX");
}
public function telegramValid(string $telegram): bool
{
return (bool) preg_match("/^(?:t.me\/|@)?([a-zA-Z0-9_]{0,32})$/", $telegram);
}
public function passwordStrong(string $password): bool
{
return (bool) preg_match("/^(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}$/", $password);
}
}