Cairns Truck School Info Site

Gravity Forms Australian Mobile Phone Number Input & Masking Code

I use Gravity Forms on this site

I love gravity forms but could never fathom why the phone codes were SO restrictive. I just wanted an aussie mobile input (XXXX XXX XXX). There are plugins that do the job, but most cost money and some have ordinary reviews.

So after a little searching on the internet I found 2 resources that permitted me to have the code and masking I want. It is very easy to add it to your functions.php file

Code here https://gist.github.com/BruceMcKinnon/544b2f57f6c161f25593ac67979299fe

Regex here https://regex101.com/r/dkFASs/6

The regex permits you to have a number of different Aussie formats such as:

I only need mobile on this site so I change the mask for that. You can see the form here: https://training.cairnstruckschool.com/backpacker-hostel-bookings/

You can open a PDF of the code I added to my functions.php file (which is found in wp-includes folder). Just add it, then tweak it to what you want.

Code is below but I suggest you copy and paste PDF code as it should be more accurate.

/**
* Adds Aussie phone formats to Gravity Forms
* Code here https://gist.github.com/BruceMcKinnon/544b2f57f6c161f25593ac67979299fe
* Regex here https://regex101.com/r/dkFASs/6
*/
add_filter( 'gform_phone_formats', 'au_phone_format' );
function au_phone_format( $phone_formats ) {
$phone_formats['au'] = array(
'label' => 'Australia',
'mask' => '9999 999 999',
'regex' => '/^04(\s?[0-9]{2}\s?)([0-9]{3}\s?[0-9]{3}|[0-9]{2}\s?[0-9]{2}\s?[0-9]{2})$/',
'instruction' => 'Australian phone numbers.',
);

return $phone_formats;
}

Cheers. I hope this is helpful.

Address: 8 Spoto Street, Woree QLD 486
Phone: 0407 471 817
Email: info@cairnstruckschool.com
ABN: 93 151 817 284
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram