Skip to content

Instantly share code, notes, and snippets.

@igorescobar
Last active April 25, 2022 07:16
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorescobar/6450250 to your computer and use it in GitHub Desktop.
Save igorescobar/6450250 to your computer and use it in GitHub Desktop.
$(".data").mask("AB/CD/0000", {
translation:{
A: {pattern: /[0-3]/},
B: {pattern: /[0-9]/},
C: {pattern: /[0-1]/},
D: {pattern: /[0-9]/},
},
onKeyPress: function(a, b, c, d) {
if (!a) return;
var m = a.match(/(\d{2})/g);
d.translation.B = (m[0] && m[0].charAt(0)=='3') ? { pattern: /[0-1]/ } : { pattern: /[0-9]/ };
d.translation.D = (m[1] && m[1].charAt(0)=='1') ? { pattern: /[0-2]/ } : { pattern: /[0-9]/ };
c.mask("AB/CD/0000", d);
}
}).keyup();
@rogeriocsilva
Copy link

@benfiratkaya thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment