Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Masking input for postal code

  • blocka
  • blocka's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
2 years 4 months ago #232127 by blocka
Masking input for postal code was created by blocka
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.28.27+220905
Own server or LimeSurvey hosting: Own
Survey theme/template: vanilla
==================
I'm looking for a way to mask input on the first 3 characters of a postal code. Codes are in format A#A -- I have Denis' masking plugin (JQuerySimpleMask) installed, but that seems to allow only for masking of numerical input. I'd like to enforce the alpha-num-alpha format... Any suggestions how to do this? It would be ideal if validation is done as the user is typing their imput.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 4 months ago #232128 by tpartner
Replied by tpartner on topic Masking input for postal code
You can use the jQuery.Mask plugin - github.com/igorescobar/jQuery-Mask-Plugin .

So, something like this in the question source (although it would be better to download the plugin and serve it locally):

Code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.js"></script>
<script type="text/javascript"  data-author="Tony Partner">
    $(document).on('ready pjax:scriptcomplete',function(){       
    $('#question{QID} input:text').mask('S0S', {
      translation: {
        '0': { pattern: /\d/ },
        'S': { pattern: /[a-zA-Z]/ }
      }
    });
    });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...3293.lss
File Size:16 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • blocka
  • blocka's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
2 years 4 months ago #232129 by blocka
Replied by blocka on topic Masking input for postal code
Beautiful! Does the job very nicely.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose