WooCommerce Code Reference

WC_Validation
in package

Validation class.

Table of Contents

format_phone()  : string
Format a given phone number.
format_postcode()  : string
Format the postcode according to the country and length of the postcode.
is_email()  : bool
Validates an email using WordPress native is_email function.
is_gb_postcode()  : bool
Check if is a GB postcode.
is_phone()  : bool
Validates a phone number using a regular expression.
is_postcode()  : bool
Checks for a valid postcode.

Methods

format_phone()

Format a given phone number.

public static format_phone(mixed $tel) : string
Parameters
$tel : mixed

Phone number to format.

Return values
string

format_postcode()

Format the postcode according to the country and length of the postcode.

public static format_postcode(string $postcode, string $country) : string
Parameters
$postcode : string

Postcode to format.

$country : string

Country to format the postcode for.

Return values
stringFormatted postcode.

is_email()

Validates an email using WordPress native is_email function.

public static is_email(string $email) : bool
Parameters
$email : string

Email address to validate.

Return values
bool

is_gb_postcode()

Check if is a GB postcode.

public static is_gb_postcode(string $to_check) : bool
Parameters
$to_check : string

A postcode.

Return values
bool

is_phone()

Validates a phone number using a regular expression.

public static is_phone(string $phone) : bool
Parameters
$phone : string

Phone number to validate.

Return values
bool

is_postcode()

Checks for a valid postcode.

public static is_postcode(string $postcode, string $country) : bool
Parameters
$postcode : string

Postcode to validate.

$country : string

Country to validate the postcode for.

Return values
bool