3 ms·
I just ran into this, I thought it would be nice to use a number input for relatively large numbers in a form, but then a user asked for a thousands separator.
by swlkr 4y ago
I just ran into this, I thought it would be nice to use a number input for relatively large numbers in a form, but then a user asked for a thousands separator.
I ditched the number input.
- ramesh31 4y agoThe (new-ish) ‘Intl.NumberFormat’ API solves this issue https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- crooked-v 4y agoNo, it doesn't. You can't apply that to a number input.
- runarberg 4y agoIt can, you just have to mask the input somehow (which can be very involved). In particular you would use numberFormat.formatToParts() and then add the parts to as the mask element interacting differently based on the type.
- sixstringtheory 4y agoI would not provide the user the ability to type a separator, but rather keep their number formatted with them in the appropriate places.
- lewisl9029 4y agoYep, this is known as input masking, and I wish browsers would just natively support this through various input types, because it's been the bane of my existence. Phone inputs are especially painful to mask since you have to deal with a mind-boggling number of format variations.