RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.4k stars 2.17k forks source link

Leading Zeros are deleted when entering #1681

Open weiser21 opened 7 years ago

weiser21 commented 7 years ago

Is there a way to prevent leading zeros from being deleted when using inputmask? I use the below code to format 4 digit account numbers. Some account numbers have leading zeros which are being deleted as the user enters their information.

        $('.integer').inputmask("numeric", {
            radixPoint: ".",
            groupSeparator: "",
            digits: 0,
            autoGroup: true,
            prefix: '', //No Space, this will truncate the first character
            rightAlign: false,
            oncleared: function () { self.Value(''); }
        });
carlos0202 commented 6 years ago

Same problem for me, i just need inputmask not to delete leading zeroes entered on some inputs with the numeric mask because they're not integer values just numeric values.

RobinHerbots commented 6 years ago

Just don't use the numeric alias for this. Use a Mask like 9{1,4} or something.

jadamec commented 5 years ago

What about fixing this after more than a year? It's a main problem I'd say... Thanks.

knoxcard commented 5 years ago

@RobinHerbots - ran into this issue as well today. Birthday input, where user has to select the day of the month.

01 02 03 ...

RobinHerbots commented 5 years ago

@knoxcard, @jadamec ,

Something like

        Inputmask("9{2}", {
            placeholder: "0",
            numericInput: true
        }).mask("test2");

? What I'm missing here?

@knoxcard ,

    Inputmask("datetime", {
            inputFormat: "dd"
        }).mask("test2");
KKS1 commented 4 years ago

For anyone else having this issue, I got this resolved with using input element of type text along with inputMode numeric PLUS having maskConfig as maskconfig: { groupSeparator: '', mask: '9{1,5}' }, where I needed a 5 digit numeric input with allowed leading zeros. Hope it helps!

berkleebytez commented 2 years ago

In my case, there was a zero in my regex that I needed to put square brackets around. Its the first zero below.

new Inputmask({ regex: "\\d{4}-(0[0-9]|[1][0-2])-([0][0-9]|[1-2][0-9]|[3][0-1])", inputmode: "numeric" }).mask(dateElement.get(0))

to 

`new Inputmask({
  regex: "\\d{4}-([0][0-9]|[1][0-2])-([0][0-9]|[1-2][0-9]|[3][0-1])",
  inputmode: "numeric"
}).mask(dateElement.get(0))`
sKopheK commented 1 year ago

in version 5.0.8-beta.20 this works for me

Inputmask('9{*}', {
    inputmode: 'numeric',
    placeholder: '',
    rightAlign: false,
}).mask(...);