WC_Validation::is_phone_formatpublic staticWC 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.

Method of the class: WC_Validation{}

No Hooks.

Returns

true|false.

Usage

$result = WC_Validation::is_phone_format( $phone ): bool;
$phone(string) (required)
Phone number to check.

Changelog

Since 11.0.0 Introduced.

WC_Validation::is_phone_format() code WC 11.0.1

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