WC_Validation::is_phone_format │ public static │ WC 11.0.0

Checks whether a string has the basic shape of a phone number, i.e. it contains only digits and characters commonly used in phone numbers (whitespace and the "# _ - + / ( ) ." characters).

Unlike is_phone, this method doesn't apply the woocommerce_validate_phone so its result always reflects the default validation rules regardless of any merchant-defined validation policy. It's intended for contexts that need a country-agnostic sanity check, such as phone number formatting.

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

Хуков нет.

Возвращает

bool.

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

$result = WC_Validation::is_phone_format( $phone ): bool;
$phone(строка) (обязательный)
Phone number to check.

Список изменений

С версии 11.0.0 Введена.

Код WC_Validation::is_phone_format() WC 11.3.0

public static function is_phone_format( $phone ): bool {
	return '' === trim( preg_replace( '/[\s\#0-9_\-\+\/\(\)\.]/', '', (string) $phone ) );
}