Inputmask icon indicating copy to clipboard operation
Inputmask copied to clipboard

Leading Zeros are deleted when entering

Open weiser21 opened this issue 6 years ago • 8 comments

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(''); }
        });

weiser21 avatar Aug 28 '17 16:08 weiser21

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.

carlos0202 avatar Dec 01 '17 19:12 carlos0202

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

RobinHerbots avatar Dec 02 '17 12:12 RobinHerbots

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

jadamec avatar Jan 16 '19 17:01 jadamec

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

01 02 03 ...

knoxcard avatar Aug 13 '19 07:08 knoxcard

@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");

RobinHerbots avatar Aug 18 '19 21:08 RobinHerbots

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!

KKS1 avatar May 08 '20 21:05 KKS1

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))`

berkleebytez avatar Dec 03 '21 19:12 berkleebytez

in version 5.0.8-beta.20 this works for me

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

sKopheK avatar Mar 29 '23 09:03 sKopheK