Skip to content

Instantly share code, notes, and snippets.

@vyskoczilova
Created January 16, 2025 16:38
Show Gist options
  • Save vyskoczilova/c5d88c7e77f3c3d5e7f2fe19c2cb123f to your computer and use it in GitHub Desktop.
Save vyskoczilova/c5d88c7e77f3c3d5e7f2fe19c2cb123f to your computer and use it in GitHub Desktop.
Phone Validator and Formatter
<?php
$phone = "555555555"; // The phone number.
$country = "us_US"; // The country selected in the address related to the phone number.
$group = "billing"; // The group of the phone number (billing, shipping).
$wc_validate_phone = true; // If WooCommerce phone validation should be used in addition.
$format = "standardize_e164"; // Standardize setting: standardize_international, no_standardize, standardize_national, standardize_e164).
$validator = \phone_validator_and_formatter()->validator();// Get validator.
$phone_is_valid = $validator->is_valid($phone, $country, $group, $wc_validate_phone);
$phone_standardized = \phone_validator_and_formatter()->standardize($phone, $country, $format)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment