Skip to content

Instantly share code, notes, and snippets.

@BruceMcKinnon
Created October 16, 2024 05:26
Show Gist options
  • Save BruceMcKinnon/3620544651802106aa599175b6a82e33 to your computer and use it in GitHub Desktop.
Save BruceMcKinnon/3620544651802106aa599175b6a82e33 to your computer and use it in GitHub Desktop.
Gravity Forms New Zealand phone number validation mask
add_filter( 'gform_phone_formats', 'nz_phone_format' );
// NZ phone format - 8, 9 or 10 digits long
function anz_phone_format( $phone_formats ) {
$phone_formats['nz'] = array(
'label' => 'New Zealand',
'mask' => '99 9999 99?99',
'regex' => '/^(?:(?:\+?64[2-9]|0[2-9])\d{6,7}|(?:\+?642\d{1}|02\d{1})\d{6,8}|(?:(?:\+?64800|0800)|(?:\+?64508|0508))\d{6,8})$/',
'instruction' => 'New Zealand phone numbers.',
);
return $phone_formats;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment