Regular Expression (Regex) for Phone Numbers – International and U.S. Formats

I have been looking all over the web for a regular expression to use in JavaScript functions to help with formatting phone number links and printing phone numbers on pages for iPhones, Android, and other mobile devices. This process would naturally affect traditional internet browsers for traditional computers but I went down this path mostly for tracking phone number touch events in Google Analytics on only mobile devices. I finally had the epiphany today that created one expression that covered most international and United States phone number formats.

International and U.S. Phone Number Regular Expression

The red areas, represent the numbered portions. Areas in gray represent the options for spaces, dashes, periods, or sometimes nothing between numbers (e.g. the question marks).
/\d?(\s?|-?|\+?|\.?)((\(\d{1,4}\))|(\d{1,3})|\s?)(\s?|-?|\.?)((\(\d{1,3}\))|(\d{1,3})|\s?)(\s?|-?|\.?)((\(\d{1,3}\))|(\d{1,3})|\s?)(\s?|-?|\.?)\d{3}(-|\.|\s)\d{4}/

Continue reading “Regular Expression (Regex) for Phone Numbers – International and U.S. Formats”

Why WordPress Main Menu Navigation is Missing from Categories

Often I am converting old WordPress sites or working with custom page or post types. When you try to force something other than posts to show in category pages, the main navigation menus fail to display. The core WordPress wp_nav_menu() function doesn’t know what to do in those cases and returns nothing.

Code Solution:

if(is_category()) {
$thiscat_id=get_query_var('cat');
$backup=$wp_query;
$wp_query = NULL;
$wp_query = new WP_Query(array('post_type' => 'any'));  }
wp_nav_menu( $defaults );
if($thiscat_id!="") { $wp_query=$backup; }

Continue reading “Why WordPress Main Menu Navigation is Missing from Categories”

Excel Tidbits: Limiting Meta Descriptions Characters and Words Like Google

I found it hard to find this information on the web, so after a little bit of work I created an Excel formula that mimics the cut off point Google may naturally use when displaying your page’s Meta description in search engine results pages (SERPs). This can come in handy when you are optimizing your site for search engines (SEO). A well written page description is very helpful in improving a site’s click through rate. Depending on your page’s subject and target audience, writing a description in which the page’s story is incomplete or leaves a person hanging improves the searcher’s interest in clicking through. As a result, the last few words of a description could play a large part in creating that situation. But if Google cuts it off too soon or too late, it may be just enough to lose a person’s interest. Continue reading “Excel Tidbits: Limiting Meta Descriptions Characters and Words Like Google”

Excel Tidbits: Creating Column Header Rows for Sorting

Apple/Mac MS Excel Column Header Selection Using Filters

Well, sad to say this one has stumped me for a long time. I work in Numbers from Apple’s iWorks Suite about as much as I do in Excel. Data sets above about 1000 rows, assuming use of processor-heavy formulas like vlookups, really slow Numbers down. From a visual and formula perspective, Numbers is much easier to use. One of my favorite aspects is the ability to create header rows so that the last row becomes the column headers and the references in formulas. That makes modifying data quicker and improves one’s ability to keep track of a greater variety of segments. Continue reading “Excel Tidbits: Creating Column Header Rows for Sorting”

Excel Tidbits: Extracting Domains from URLs Function

Excel LogoiWorks Numbers LogoI often mash and extract data using Excel. I needed a way to pull out the domain from a web address and compare it with domains from other sheets and activities. This then gives me insight into how often we do work on websites across all our projects.

Version Note: The formula below only works in versions of Excel that can read the xlsx format. Older versions of Excel (pre-2004) are limited to seven nested formulas. This equation has eight. The iserror formulas in the if statements checks for errors and displays whatever is in the A6 cell if an error occurs. If the cell is blank, it should stay blank. I simply used the blank check upfront to make the formula more efficient in processing. Continue reading “Excel Tidbits: Extracting Domains from URLs Function”