2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-12-08 21:06:05 +03:00
|
|
|
namespace openvk\Web\Util;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2021-12-08 21:06:05 +03:00
|
|
|
use Chandler\Patterns\TSimpleSingleton;
|
|
|
|
|
|
|
|
class Validator
|
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
use TSimpleSingleton;
|
|
|
|
public function emailValid(string $email): bool
|
2021-12-08 21:06:05 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if (empty($email)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-08 21:06:05 +03:00
|
|
|
|
|
|
|
$email = trim($email);
|
|
|
|
[$user, $domain] = explode("@", $email);
|
2025-01-31 18:20:13 +03:00
|
|
|
if (is_null($domain)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (iconv_strlen($user) > 64) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-08 21:06:05 +03:00
|
|
|
$domain = idn_to_ascii($domain) . ".";
|
|
|
|
|
|
|
|
return checkdnsrr($domain, "MX");
|
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function telegramValid(string $telegram): bool
|
2021-12-08 21:06:05 +03:00
|
|
|
{
|
2021-12-08 23:19:16 +03:00
|
|
|
return (bool) preg_match("/^(?:t.me\/|@)?([a-zA-Z0-9_]{0,32})$/", $telegram);
|
2021-12-08 21:06:05 +03:00
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function passwordStrong(string $password): bool
|
|
|
|
{
|
2023-04-19 14:02:33 +03:00
|
|
|
return (bool) preg_match("/^(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}$/", $password);
|
|
|
|
}
|
2021-12-08 21:06:05 +03:00
|
|
|
}
|