WooCommerce Code Reference

Search results

WC_Validation

Validation class.

Table of Contents

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

Methods

is_email()

Validates an email using WordPress native is_email function.

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

Email address to validate.

Return values
bool

is_phone()

Validates a phone number using a regular expression.

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

Phone number to validate.

Return values
bool

is_postcode()

Checks for a valid postcode.

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

Postcode to validate.

$country : string

Country to validate the postcode for.

Return values
bool

is_gb_postcode()

Check if is a GB postcode.

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

A postcode.

Return values
bool

format_postcode()

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

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

Postcode to format.

$country : string

Country to format the postcode for.

Return values
string

Formatted postcode.

format_phone()

Format a given phone number.

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

Phone number to format.

Return values
string
Back to the top