Jump to content

Autoformat of Canadian postal code


Recommended Posts

Hi @JanineB - if you would like to autoformat the text when you are typing and limit to only 6 characters, you may use Cleave.js . For more info, you may check it here: https://nosir.github.io/cleave.js/

To apply this in the Submission Form, insert a Header and Footer and paste this code in the Footer:

<script src="https://cdnjs.cloudflare.com/ajax/libs/cleave.js/1.6.0/cleave.min.js" integrity="sha512-KaIyHb30iXTXfGyI9cyKFUIRSSuekJt6/vqXtyQKhQP6ozZEGY8nOtRS6fExqE4+RbYHus2yGyYg1BrqxzV6YA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script>

var cleave = new Cleave('#InsertRecordFIELDNAME', {
    blocks: [3,3],
    uppercase: true
}); //Format the input


document.addEventListener('BeforeFormSubmit', function(event) {

var ad = document.querySelector("input[name='InsertRecordFIELDNAME']").value;


	function is_caPostalCode(str) {
      	regexp = /^([A-Z][0-9][A-Z])\s*([0-9][A-Z][0-9])$/;
      
      	if (regexp.test(str)==false) {
          event.preventDefault();
          alert("Postal Code invalid");
        }
    }

	is_caPostalCode(ad);
  
});
// check if the postal code is invalid or not

</script>

Make sure to disable the HTML Editor in the Advanced tab of the Footer.

Hope this helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...