openvk/Web/Util/Validator.php
Локоток 2f8612bb24
Проверка на надежный пароль (#862)
* Проверка на надежный пароль

* fixed typos in locales/ru.strings

Co-authored-by: Alexander Minkin <weryskok@gmail.com>

* подправил локаль

---------

Co-authored-by: Alexander Minkin <weryskok@gmail.com>
2023-04-19 14:02:33 +03:00

30 lines
809 B
PHP

<?php declare(strict_types=1);
namespace openvk\Web\Util;
use Chandler\Patterns\TSimpleSingleton;
class Validator
{
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");
}
function telegramValid(string $telegram): bool
{
return (bool) preg_match("/^(?:t.me\/|@)?([a-zA-Z0-9_]{0,32})$/", $telegram);
}
function passwordStrong(string $password): bool{
return (bool) preg_match("/^(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}$/", $password);
}
use TSimpleSingleton;
}