<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Automatic Phone Number and Postal Code Field Formatting in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/699090#M30613</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/189936"&gt;@lait&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/103660"&gt;@piersg&lt;/a&gt;'s solution is a good one and should stop a lot of your problems right at the source.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, you might run into some issues with phone number formatting, as there are just so many variables to consider. What kind of validation do you have on the form? Are you certain they will enter phone numbers like you described (or at least the in-flowing data will be that way by the time formatting takes place? For example, could a user enter a phone number in different formats like "123.456.8675" or "+1-425-532-7864,"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Accounting for different formats, area codes, country-specific formats, and country codes can get extremely messy. If you knew for certain your CRM entries were from a specific country or had strong validation don't he form field that severely limits the issue that you have to take into account, though.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are dealing with advanced issues like that, I would recommend trying &lt;A href="https://app.hubspot.com/ecosystem/6303986/marketplace/apps/marketing/data-management/insycle" target="_blank" rel="noopener"&gt;Insycle&lt;/A&gt;. Full disclosure, I work for Insycle, but it can help solve some advanced use cases regarding phone number formatting:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Many pre-built phone number formatting templates&lt;/LI&gt;&lt;LI&gt;Build custom phone number formatting templates&lt;/LI&gt;&lt;LI&gt;Format phone numbers for country codes (based on location data)&lt;/LI&gt;&lt;LI&gt;Include phone number formatting recipes in HubSpot Workflows, so that your phone number field is formatted directly after the data hits HubSpot CRM and before your first marketing or sales materials go out&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In short, phone number formatting quickly becomes a complex topic when you look at all of the potential variables.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 20:00:03 GMT</pubDate>
    <dc:creator>RBozeman</dc:creator>
    <dc:date>2022-09-27T20:00:03Z</dc:date>
    <item>
      <title>Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/472593#M24363</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a submission &lt;A href="https://share.hsforms.com/1SVHk8SiDTMm8oGlCFHUjCAbuyf5" target="_blank" rel="noopener"&gt;form&lt;/A&gt; and I was wondering if it is possible to force the formatting when the user enters the the phone number and postal code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if a user enters a Canadian phone number this way: 123456789, is it possible to&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;automatically populated this format: (123) 456 789?&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;Same for postal codes: s0s-0s0 to S0S 0S0?&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;I have tried using this code in our &lt;A href="https://app.hubspot.com/design-manager/19920065/code/50183452798?tfid=49174042507" target="_blank" rel="noopener"&gt;field_masks.js&lt;/A&gt; file:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function() {
  // Post code mask
	$('input[name="zip"]').mask('S0S 0S0');
 
  // Phone number mask
  $('input[name="phone"]').mask('p1 (000) 000-0000', {
        translation: {
            p: {
                pattern: /\+/,
                optional: true
            }
        }
    });
//     return this.optional(element) || /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i.test(value);
//   }, "Please provide a valid zipcode.");
}());
$('input[type=email]').bind('input', function () {
        $(this).val(function (_, v) {
            return v.replace(/\s+/g, '');
        });
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;But it does not work. Is that even possible?&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 16:12:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/472593#M24363</guid>
      <dc:creator>lait</dc:creator>
      <dc:date>2021-08-04T16:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/473567#M24376</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/103660"&gt;@piersg&lt;/a&gt;&amp;nbsp; can probably help out here &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 15:56:12 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/473567#M24376</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-08-05T15:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/473632#M24377</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/189936"&gt;@lait&lt;/a&gt;, you can use this function for the phone number&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;function formatPhoneNumber(phoneNumberString) {
  var cleaned = ('' + phoneNumberString).replace(/\D/g, '');
  var match = cleaned.match(/^(\d{3})(\d{3})(\d{3})$/);
  if (match) {
    return '(' + match[1] + ') ' + match[2] + ' ' + match[3];
  }
  return null;
}
// example:
formatPhoneNumber(123456789)
// outputs "(123) 456 789"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the post codes you can do this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;function formatPostCode(postCode){
    return postCode.toUpperCase().replace('-',' ');
}
formatPostCode('s0s-0s0');
// outputs "S0S 0S0"&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 Aug 2021 17:07:18 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/473632#M24377</guid>
      <dc:creator>piersg</dc:creator>
      <dc:date>2021-08-05T17:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/477018#M24436</link>
      <description>&lt;P&gt;Thanks for the help! However (and again I'm sorry, I am new to this tool), I have modified the JS file, but then I don't know where to customize the form in the HTML version so I can apply the JS to in my &lt;A href="https://app.hubspot.com/design-manager/19920065/code/50185179780?tfid=49174042507" target="_blank" rel="noopener"&gt;Design Manager&lt;/A&gt;... I did not find a form mudule. Am I missing something? &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 21:11:58 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/477018#M24436</guid>
      <dc:creator>lait</dc:creator>
      <dc:date>2021-08-10T21:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/477362#M24440</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/189936"&gt;@lait&lt;/a&gt;&amp;nbsp;How are you adding the form to the page? Are you using the embed code, or are you doing it in a module?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're using an embed code I would do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;!--[if lte IE 8]&amp;gt;
&amp;lt;script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;![endif]--&amp;gt;
&amp;lt;script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
	hbspt.forms.create({
		portalId: "[portal id]",
		formId: "[form id]"
	});
	function formatPhoneNumber(phoneNumberString) {
	  var cleaned = ('' + phoneNumberString).replace(/\D/g, '');
	  var match = cleaned.match(/^(\d{3})(\d{3})(\d{3})$/);
	  if (match) {
	    return '(' + match[1] + ') ' + match[2] + ' ' + match[3];
	  }
	  return null;
	}

	function formatPostCode(postCode){
	    return postCode.toUpperCase().replace('-',' ');
	}

    window.addEventListener('message', event =&amp;gt; {
		if(event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormSubmit') {
			var postCode = document.getElementById('zip-input');
			var phone = document.getElementById('0-2/phone-input');
			postCode.value = formatPostCode(postCode.value);
			phone.value = formatPhoneNumber(phone.value);
		}
	});
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if you're using a custom module you can add a form field that allows you to select the form you want in the page editor&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="piersg_0-1628675341163.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/48023i0D0F3ED74D582DF8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="piersg_0-1628675341163.png" alt="piersg_0-1628675341163.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then add this to the JS section of the module&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;function formatPhoneNumber(phoneNumberString) {
  var cleaned = ('' + phoneNumberString).replace(/\D/g, '');
  var match = cleaned.match(/^(\d{3})(\d{3})(\d{3})$/);
  if (match) {
    return '(' + match[1] + ') ' + match[2] + ' ' + match[3];
  }
  return null;
}

function formatPostCode(postCode){
  return postCode.toUpperCase().replace('-',' ');
}

window.addEventListener('message', event =&amp;gt; {
  if(event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormSubmit') {
    var postCode = document.getElementById('zip-input');
    var phone = document.getElementById('0-2/phone-input');
    postCode.value = formatPostCode(postCode.value);
    phone.value = formatPhoneNumber(phone.value);
  }
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 09:52:20 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/477362#M24440</guid>
      <dc:creator>piersg</dc:creator>
      <dc:date>2021-08-11T09:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/565451#M27081</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is it possible ot make mask phone number field in a form? Can't find&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 13:58:17 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/565451#M27081</guid>
      <dc:creator>BSCARAVELLI</dc:creator>
      <dc:date>2022-01-29T13:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/699090#M30613</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/189936"&gt;@lait&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/103660"&gt;@piersg&lt;/a&gt;'s solution is a good one and should stop a lot of your problems right at the source.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, you might run into some issues with phone number formatting, as there are just so many variables to consider. What kind of validation do you have on the form? Are you certain they will enter phone numbers like you described (or at least the in-flowing data will be that way by the time formatting takes place? For example, could a user enter a phone number in different formats like "123.456.8675" or "+1-425-532-7864,"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Accounting for different formats, area codes, country-specific formats, and country codes can get extremely messy. If you knew for certain your CRM entries were from a specific country or had strong validation don't he form field that severely limits the issue that you have to take into account, though.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are dealing with advanced issues like that, I would recommend trying &lt;A href="https://app.hubspot.com/ecosystem/6303986/marketplace/apps/marketing/data-management/insycle" target="_blank" rel="noopener"&gt;Insycle&lt;/A&gt;. Full disclosure, I work for Insycle, but it can help solve some advanced use cases regarding phone number formatting:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Many pre-built phone number formatting templates&lt;/LI&gt;&lt;LI&gt;Build custom phone number formatting templates&lt;/LI&gt;&lt;LI&gt;Format phone numbers for country codes (based on location data)&lt;/LI&gt;&lt;LI&gt;Include phone number formatting recipes in HubSpot Workflows, so that your phone number field is formatted directly after the data hits HubSpot CRM and before your first marketing or sales materials go out&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In short, phone number formatting quickly becomes a complex topic when you look at all of the potential variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 20:00:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/699090#M30613</guid>
      <dc:creator>RBozeman</dc:creator>
      <dc:date>2022-09-27T20:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Phone Number and Postal Code Field Formatting</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/781057#M33774</link>
      <description>&lt;P&gt;Running into this issue now, just imported roughly 4,500 contacts from another CRM. A decent split between Canadian and US phone numbers, and am now stuck going through every single one to format CAN/US phone numbers. A very simple filter on my spreadsheet would break them into 2 categories, and in 2 clicks I could format all 4,500 numbers if this tool was available.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Considering this thread was started 2 years ago I won't hold my breathe, but I thought i'd add to it and hopefully give it some attention.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Hubspot, please listen to the people who actually use your software before they start going elsewhere.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 19:00:24 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Automatic-Phone-Number-and-Postal-Code-Field-Formatting/m-p/781057#M33774</guid>
      <dc:creator>GMoore0</dc:creator>
      <dc:date>2023-04-12T19:00:24Z</dc:date>
    </item>
  </channel>
</rss>

