Skip to content

Instantly share code, notes, and snippets.

@lucasbrigida
Created November 24, 2016 04:18
Show Gist options
  • Save lucasbrigida/76533a0a44f7d528a7c3c958e0c0f043 to your computer and use it in GitHub Desktop.
Save lucasbrigida/76533a0a44f7d528a7c3c958e0c0f043 to your computer and use it in GitHub Desktop.
(function($){
/*CUSTOM PHONE TAG */
$(function(){
var tag = 'phone';
var tagSelector = '.profile div:contains("'+tag+'")';
var tagValue = jQuery(tagSelector).first().text();
//if (!tagValue) return;
var tagPrettyValue = tagValue.replace('['+tag+'=\"', '').replace('\"]', '');
var tagRawValue = tagPrettyValue.replace('(', '').replace(')', '').replace(' ', '').replace('-', '');
var tagRegexp = /^\(?[1-9]{2}\)?\s?\d{4,5}(\-|\s)?\d{4}$/gm;
var tagTemplate = '<a href="tel:'+tagRawValue+'">'+tagPrettyValue+'</a>';
if (tagRegexp.test(tagRawValue) === true) jQuery(tagSelector).first().html(tagTemplate);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment