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_phone_format() : bool
- 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).
- 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
string — Formatted 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[, string|null $country = null ]) : bool
Parameters
- $phone : string
-
Phone number to validate.
- $country : string|null = null
-
The country code the phone is being validated for, or null if unknown.
Return values
bool —is_phone_format()
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).
public
static is_phone_format(string $phone) : bool
Unlike is_phone, this method doesn't apply the woocommerce_validate_phone filter,
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.
Parameters
- $phone : string
-
Phone number to check.
Tags
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.
