RockLobsterInc\Swv\Rules

TelRule::isTel │ public static │ CF7 1.0

Returns true if the given string is a well-formed telephone number.

Метод класса: TelRule{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = TelRule::isTel( $value ): bool;
$value(строка) (обязательный)
String to check.

Код TelRule::isTel() CF7 6.2.4.1

public static function isTel(string $value): bool
{
    $value = preg_replace('/[#*].*$/', "", $value); // Remove extension.
    $value = preg_replace("%[()/.*#\s-]+%", "", $value);

    $is_international =
        "+" === substr($value, 0, 1) || "00" === substr($value, 0, 2);

    if ($is_international) {
        $value = "+" . preg_replace("/^[+0]+/", "", $value);
    }

    if (!preg_match('/^[+]?[0-9]+$/', $value)) {
        return false;
    }

    if (!(5 < strlen($value) and strlen($value) < 16)) {
        return false;
    }

    return true;
}