• Roundup WP
  • Products
    • Registrations for the Events Calendar Pro – WordPress Event Registration
      • Buy Now
      • Setup (Pro)
      • Demo
    • Stripe Extension
      • Buy Now
      • Setup
    • Mailchimp Extension
      • Buy Now
      • Setup
    • RTEC Memberships
      • Getting Started
    • RTEC WooCommerce Payments
    • Mollie (iDEAL) Extension
      • Buy Now
      • Setup
    • Discount Codes Extension
      • Buy Now
      • Setup
  • Pricing
  • Features
    • Payments
    • Form Builder
    • Email Messages
    • Registration Management
    • Memberships
    • Event Specific
  • Blog
  • Support
    • FAQs and Troubleshooting
    • Codex
    • Contact Support
  • My Account
  • Get Started

How to Format Phone Numbers

Last updated on February 24, 2017

The plugin will attempt to output phone numbers in an easy-to-read format based on the number of digits in the phone number submitted by the attendee.

You can format the display of 10 digit numbers using the setting in the “Advanced” area near the bottom of the “Form” tab. For further customization, you can use a snippet of php code added to either a custom plugin or your theme’s functions.php file:

function rtec_phone_rules( $rules ) {
  $rules[11] = array(
    'pattern' => '/([0-9]{3})([0-9]{4})([0-9]{4})/',
    'replacement' => '$1 $2 $3'
  );

  return $rules;
}
add_filter( 'rtec_phone_formatting_rules', 'rtec_phone_rules', 10, 1 );

This example will format any 11 digit phone number to be outputted with the first three digits, then next 4 digits, then the last 4 digits (ex. 123 4567 8901)

The code breaks down like this:

$rules[11] = array(

The number of digits this rule applies to (11)

'pattern' => '/([0-9]{3})([0-9]{4})([0-9]{4})/',

How the numbers will be grouped (3 total groups of 3, 4, and 4)

'replacement' => '$1 $2 $3'

How the groups will be outputted. $1 is the first group which is the first 3 digits in our example. $2 is the second group which is the middle 4 digits. $3 is the last group which is the last 4 digits in our example.

Do you need multiple new formats? You can add as many as needed by adding multiple “rules”

function rtec_phone_rules( $rules ) {
  $rules[10] = array(
    'pattern' => '/([0-9]{1})([0-9]{3})([0-9]{3})([0-9]{3})/',
    'replacement' => '+$1 $2 $3 $4'
  );

  $rules[11] = array(
    'pattern' => '/([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{3})/',
    'replacement' => '+$1 $2 $3 $4'
  );

  $rules[12] = array(
    'pattern' => '/([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{3})/',
    'replacement' => '+$1 $2 $3 $4'
  );

  return $rules;
}
add_filter( 'rtec_phone_formatting_rules', 'rtec_phone_rules', 10, 1 );

Pattern Examples:

Do you have example of formats for your specific locale? Please submit them using our form here so we can add examples to this page others can use.

Example: ( 12 34 56 78 90 )

$rules[10] = array(
  'pattern' => '/([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',
  'replacement' => '( $1 $2 $3 $4 $5 )'
);

Example: +4 123 123 123

$rules[10] = array(
  'pattern' => '/([0-9]{1})([0-9]{3})([0-9]{3})([0-9]{3})/',
  'replacement' => '+$1 $2 $3 $4'
);

Example: +24 123 123 123

$rules[11] = array(
  'pattern' => '/([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{3})/',
  'replacement' => '+$1 $2 $3 $4'
);

Example: +242 123 123 123

$rules[12] = array(
  'pattern' => '/([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{3})/',
  'replacement' => '+$1 $2 $3 $4'
);

Need help? Contact us here.

Company
  • About
  • Contact
  • Careers
Products
  • Registrations for the Events Calendar
  • Stripe Payments (extension)
  • Mailchimp Email Lists (extension)
  • Event Memberships (extension)
  • WooCommerce Payments (extension)
  • Mollie iDEAL Payments (extension)
  • Discount Codes (extension)
Features
  • Form Builder
  • Event Registration Payments
  • Membership Features
  • Email Messaging
  • Registration Management
  • Event Specific
Resources
  • Support
  • My Account
  • Documentation
  • Pricing
  • Blog
Connect with Us
Follow us on Facebook Contact Us
Copyright © 2025 Roundup WP LLC
Terms & Conditions Privacy Policy Roundup WP Coupon Codes