Australian Mobile Validation CakePHP 3.x

Written by James McDonald

August 27, 2018

This is a very simple mobile validation for Australian Mobiles. It probably would also benefit from having all the symbols except + stripped too

// src/Model/Table/Users.php where Users is the class name
// of the table field your are validating
$australianMobile = '/^(0|\+61)4\d{8}$/';

      ->add('mobile_number', 'custom', [
                'rule' => function ($value, $context) use ($australianMobile) {
                    // remove spaces to make the regex simpler
                    $check = preg_replace('/\s/', '', $value);
                    // checks for either of these styles
                    // +61412 345 678 or 0412 345 678
                    $found = preg_match($australianMobile, $check);
                    return boolval($found);
                'message' => 'Please enter a valid mobile number.'


Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language The above website has a page where you can enter ZPL and it...

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...

PHP array_map Multiple Arrays

array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each...