JanineB Posted March 30, 2022 Report Share Posted March 30, 2022 Is there a way for a field to autoformat to Canadian Postal Code? The format should be: Letter, Number, Letter, Space, Number, Letter, Number For example: H4Z 9Z9 Thanks! Quote Link to comment Share on other sites More sharing options...
Meekeee Posted March 30, 2022 Report Share Posted March 30, 2022 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! JanineB 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.