Phone numbers have got to be one of the most commonly gathered bits of information in forms. I created a little PHP function that formats them for the most common US strings, 7 or 10 digits.

The Function

// FORMAT PHONE NUMBERS
function formatPhoneNumber($variableName) {
  global $$variableName;
  // Keep numbers only
  $$variableName = ereg_replace("[^0-9]", "", $$variableName );
  // Remove "1" if it's the first character
  $$variableName = preg_replace("/^1/", "", $$variableName);
  // format for 7 digit numbers
  if(strlen($$variableName) == 7)
    $$variableName = preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $$variableName);
  // format for 10 digit numbers
  if(strlen($$variableName) == 10) // 10 digit numbers
    $$variableName = preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $$variableName);
}

Calling the Function

if (isset($_POST['phoneNumber'])) {
  $phoneNumber = addslashes($_POST['phoneNumber']);
  formatPhoneNumber('phoneNumber');
}
// Do something with the phone number, i.e. insert into a db...

Things This Doesn’t Account For:

Obviously, this does not perform any form validation. If anything other than a 7 or 10 digit number is submitted, it will only be stripped down to numbers.

Permanently moving one domain to another is a huge task. Creating a single redirect for each page on your site is unrealistic and would suck the very life from your body. Well, relax – there’s an easier way, using htaccess. This will redirect all of your pages to their respective new pages on your new domain. Continue reading

When adding a phone number field to a form, it’s nice to format it (if it isn’t already). This doesn’t replace anything you would do to validate your form via Javascript. But it does create that little extra bit of uniformity, even if it is slightly redundant.

Update: I have updated this a bit and created a reusable function. You can find it hereContinue reading

Working with WordPress and Bootstrap, you might be frustrated with the built in menu options. There isn’t an easy way to tell WordPress to swap out the  current-menu-item class with bootstrap’s active class. Fortunately for you and me, there’s jQuery for that. Just a little dab will do ya.

jQuery(document).ready(function () {
  $(".current-menu-item").addClass("active");
});

This little blessed bit of jQuery will add the active class to your menu on the fly.

Creating custom functions in your WordPress template’s function.php file is a regular thing for many of us. What you might not know is how easy it is to wrap them in a class, or even why you would. Wrapping them in a class keeps them both organized and self-contained from other functions that may have the same name. This can be especially important if you are using third party plugins. Continue reading

The process of recording music has three steps these days.

  1. Tracking (or more simply put, recording the individual parts of the song),
  2. Mixing (making all of the adjustments, tweeks, and special effects after recording), and
  3. Mastering (Polishing up the final product).

As a producer of my own music, I often run into the temptation to get ahead of myself in these processes. I’ll hear a song I’m writing, and want to start mixing before I’m finished writing it. The next thing I know, I’ll have mastered the thing too. Big mistake! Maybe you’ve done it too. Continue reading

In episode four of this multi-part series on the future on online banking, I show retail financial institutions the right — and wrong — ways to manage the never-ending cycle of change required in this critical channel.

Read the entire article, The Future of Online Banking: A Culture of Change, on The Financial Brand.

I recently set out to customize WordPress profile fields for a specific role. You may want to have custom fields for users, but have different fields for different roles. For example, Authors may need some additional contact information, while Subscribers need only some basic fields. The concern I had was wether or not an Admin would be able to pull up any profile and edit all of the fields. Here’s the solution I found. Continue reading