Some masks for InputMask (field with dynamic input mask)

Share your custom code, plugins and themes.
Post Reply
Didou12
Posts: 487
Joined: 14 Jan 2023, 14:53
Name: Louis
Location: Montreal, Canada

Some masks for InputMask (field with dynamic input mask)

Post by Didou12 »

Here some masks you can use.

Note :
- mask : is the mask (it's not a regex) with definitions
- greedy (default true) : false or true, if true "mandatory and non-variable characters" of a mask (such as a space (postal code) or a dash (phone number)) are automatically filled in.
- clearIncomplete (default false) : true or false, if true when the input loses the focus (user clicks outside) and the mask is not complete, the field is automatically cleared.
- definitions : is authorized characters for the mask.
- casing : upper or lower, make the charactes in uppercase; so you can define a validator like [A-Za-z] (user can types upper or lower characters), and the characters are automatically in uppercase.


  • For a USA/Canada postal code

Code: Select all

{
  mask: 'A9A 9A9',
  clearIncomplete: true,
  definitions: {
    'A': {
      validator: "[A-Za-z]",
      casing: "upper"
    },
    '9': {
      validator: "[0-9]"
    }
  }
}

  • Characters A-Z or a-z, 0 to 5 characters, automatically in uppercase

Code: Select all

{
  mask: "*{0,5}",
  greedy:false,
  definitions: {
    '*': {
      validator: "[a-zA-Z]",
      casing: "upper"
    }
  }
}

  • One dash or none

Code: Select all

{
  mask: "*{0,1}",
  greedy:false,
  definitions: {
    '*': {
      validator: "[-]"
    }
  }
}

  • 1 or more numbers (no limitation)

Code: Select all

{
  mask: "*{1,}",
  greedy:false,
  definitions: {
    '*': {
      validator: "[0-9]"
    }
  }
}


Hope it can help :)
Using Rukovoditel since 2022 --- v3.4 (with extension) in French on PHP 8.2
I keep the French translation up to date
I'm trying to help you (+10 years experience in html, css, php, sql, JS/jquery, python)
brave
Sponsor
Sponsor
Posts: 180
Joined: 17 Jul 2016, 12:34
Name: Patrick
Location: Germany

Re: Some masks for InputMask (field with dynamic input mask)

Post by brave »

Hello and thank you for letting us be a part of it. I use your code to learn and understand, that always helps me a little bit further in my concerns. Simply tool!
Didou12
Posts: 487
Joined: 14 Jan 2023, 14:53
Name: Louis
Location: Montreal, Canada

Re: Some masks for InputMask (field with dynamic input mask)

Post by Didou12 »

My pleasure,

I will edit my post in the next few days to add a method to have dynamic mask based on value from a field.
Using Rukovoditel since 2022 --- v3.4 (with extension) in French on PHP 8.2
I keep the French translation up to date
I'm trying to help you (+10 years experience in html, css, php, sql, JS/jquery, python)
Post Reply