jquery-meiomask
jquery-meiomask copied to clipboard
Optional mask characters
Hi,
Is it possible to define a mask with optional characters? I can't find any information in the demo's or the homepage about this. Such a mask would perhaps look like:
AAAA[AA]
Where only four characters are necessary. Obviously there are edge cases related to separated optional characters, but it's something pretty much every other masking library supports.
I really love the paste abilities, and the rest of the plugin looks pretty good. I'd love to use it, but this is holding me back.
Cheers
Me too. The inability to define an optional part holds me back too. http://digitalbush.com/projects/masked-input-plugin/ has it.
it should be a ? or grouping, like you showed above, I was searching the docs for this option, being used to the masked input, and it's not available...
I need the same functionality. I need to create a mask with a phone digit optional towards the end: (99) 9999-9999?9 Is there any way to do it?
Celular de São Paulo ftw :P
did you guys try something like this:
// 'n' can be any char of your choice
$.mask.rules.n = /[0-9]?/
and then defining the mask as:
(99) 9999-9999n
In this case the last number would be optional.
Does this solve the problem?
Isso mesmo, funcionou perfeitamente. Obrigado!
How to give the first number as optional. for time the available values for first digit is 0,1,2. If I give 3 then it should be always 03 only. But giving 3 directly is not accepting. Can anyone provide me the solution for it.
Adding a new rule like $.mask.rules.n = /[0-9]?/ will allow letters and symbols too.
App.phone = {
overflow: function (character) {
var $that = $(this);
if (character.match(/[0-9]/)) {
$that
.setMask('(99) 99999-9999').val($that.val() + character)
.on('keyup', App.phone.keyup);
}
},
keyup: function (event) {
if (event.keyCode == 8 || event.keyCode == 46) {
$(this).setMask($.mask.masks.phone);
}
}
}
$.mask.masks.phone = { mask: '(99) 9999-9999', autoTab: false, onOverflow: App.phone.overflow };
$(':input').setMask();
This solution is completely functional, created by @marcelofraga.
try this:
$.mask.rules.n = /[0-9]\d{0}?/