11 ms·
My personal pet-peeve is devs using the number input for things that contain digits but aren't "numbers" (credit card numbers, 2fa codes, postal codes etc)[0].
by kilian 4y ago
My personal pet-peeve is devs using the number input for things that contain digits but aren't "numbers" (credit card numbers, 2fa codes, postal codes etc)[0]. Number input provides a lot of footguns and you're usually better off using something else.
[0] https://kilianvalkhof.com/2022/css-html/are-you-sure-thats-a-number-input/ https://kilianvalkhof.com/2022/css-html/are-you-sure-thats-a...
- madeofpalk 4y agoThe most infuriating part about number input, is when you set min=0, you can't backspace in the field to enter a different number.
- Zardoz84 4y agoI don't see that behavior on Firefox and Chromium ... What browser dos that ?
- padseeker 4y agoI actually mentioned that at the bottom of the article on how to handle the issues mentioned. Firmly agreed, using the number input for non mathematical values is a horrible idea.
- xxr 4y agoA former employer had a system that consumed phone calls from Twilio. The phonecall table had a touchtoneinput column for the sequence of digits a caller pushed after the call connected (press 1 for English, press 3 to dispute a charge, etc.). We would sporadically get these query errors on inserts--turned out the touchtoneinput column was defined as a bigint, and the rare occasions where a caller pressed the # or * keys were sending input that obviously could not be parsed as an integer. Good rule of thumb: if a reasonable person calls it a number, but your application is never going to perform arithmetic on it[0], it should probably just be a string. [0]: Yes, a credit card number can be checksummed, but that's more in the sense of a CC# being a sequence of numbers rather than one int.
- londons_explore 4y agoThere are actually 4 more touch tones possible - A, B, C and D. Sometimes you can get into secret menus if you play the tones for them...
- jbverschoor 4y agoHow do I enter these from an iphone? Or should I just let my laptop output the dtmf tones? I'm def. gonna try this out. I usually pres & and # a couple of times, because it often skips the useless menus and takes me to a person
- sshine 4y ago> should I just let my laptop output the dtmf tones? Yes. Depending on your OS, it might even have the sound files: https://osxdaily.com/2016/03/31/play-dtmf-tones-mac/ https://osxdaily.com/2016/03/31/play-dtmf-tones-mac/
- jbverschoor 4y agoCool!, but that doesn't include ABCD. https://pbxbook.com/other/dtmftone.html https://pbxbook.com/other/dtmftone.html does. I'll try a company I know takes at least 40 minutes usually : Also, something that annoys me about VOIP is that they don't take into account the different tones in different regions. Here in the Netherlands we use 425Hz fo dial tone etc. It always feels very emulated because it's a different tone.
- hnuser123456 4y agoI've found pressing 0 or 1 usually works too
- Someone 4y agoHistorically, you whistled them (https://en.wikipedia.org/wiki/Phreaking https://en.wikipedia.org/wiki/Phreaking), or you bought a hardware ‘whistle’ from the likes of Steve Jobs (https://en.wikipedia.org/wiki/Blue_box https://en.wikipedia.org/wiki/Blue_box)
- hbn 4y agoMy credit card number is three quadrillion, five hundred and twenty-eight trillion, nine hundred and seventeen billion...
- fsckboy 4y agojust as a bit of trivia, not sure where this even comes from, Dickensian counting houses? but you're not supposed to put the word "and" in there, just strip it out; say "and" when you get to the decimal point
- airstrike 4y agothe "and" is there in other languages so maybe it's just a translation oversight ;-)
- kccqzy 4y agoThe "and" after "hundred" is just standard British English. American English omits that "and" though.
- fsckboy 4y agobut it makes an actual difference in unambiguous comprehension, like the Oxford comma. "one hundred seventeen" vs "one hundred and seventeen" are different, 117 vs 100.17 "twenty three eights" vs "twenty and three eighths" are 23/8 vs 20 3/8. I don't know why this idea is upsetting to people. https://www.grammar-monster.com/lessons/numbers_how_to_write_in_full.htm https://www.grammar-monster.com/lessons/numbers_how_to_write...
- cafard 4y agoYears ago, a report somebody had built for us blew up on some addresses in the Midwest. A look at the addresses showed values of the form "12345E State Road 5". The control that read the house number interpreted as a number in scientific format, and of course had no provision for a number that large. Dropping a space in before the "E"s allowed the report to run. This is an odd case, in that the house number is a "number": in the US it generally indicates distance from some fixed line, and the parity can indicate which side of the street it falls on. But then people will write them with As, Bs, Es, etc. attached.
- kube-system 4y agoIf something is sometimes a number, then it’s not a number. Address numbers in the US are just identifiers that use digits, and sometimes they are derived from some other factor that is a (or multiple!) number.
- vsareto 4y agoSomeone should write a bot to post a reminder to "start with strings unless you're doing math" to reddit/twitter/youtube every week and the world would probably be way better for it. We could even have compiler warnings for type-safe languages when someone declares an int with a name containing 'address/zip/postal/credit/card'
- r-w 4y ago> We could even have compiler warnings for type-safe languages when someone declares an int with a name containing 'address/zip/postal/credit/card' That sounds like it would be a better job for a linter than for a compiler.
- gibolt 4y agoWhy not both! Not everyone uses a linter (unfortunately). Compiler would be a nice second catch (for any tooling that has a compiler)
- fsckboy 4y ago
- chrsig 4y agoi have an insurer who uses social security numbers as account numbers...and stores them as integers. the developers obviously did not realize that social security numbers may start with a leading zero. (so can postal codes!)
- fwip 4y agoThis can clearly cause output formatting issues, but it doesn't seem to introduce any ambiguity as they're all 9 digits.
- deleted 4y ago[deleted]
- px1999 4y agoA bit of a side point but I'm a little amazed that using ssns as account ids is legal. The approach just seems to be asking for identity theft/fraud...
- somat 4y agoPersonally I am conflicted on this one. On the one hand a ssn number(or any identifying number) should not need to be any more secret than the name it is replacing, your ssn should be able to be publicly available. However, this is the real world and many people and institutions use the ssn as the sole source of identity, which means it needs to be kept secret.
- lucas_membrane 4y agoUnfortunately, about 40 years ago, I was employed by a corporation in a capacity that required them to file documents identifying me by SSN to state regulators in several states, such documents being available for the public to inspect, not withstanding that I still have my original Social Security card, which says thereon quite clearly "Not for Identification." The SSN does not have the attributes of a good permanent identifier of a unique person. If you get an SSN with three consecutive 6's in it, you can get it changed to another one not containing that string. Worse yet, the Social Security Administration has reserved the right to reuse the SSN's of persons deceased (IDK if they can or might do that without giving further notice). Furthermore, the US government talks as if there are two completely different kinds of numbers that each use 9 digits, and that they might overlap, ie use the same numbers for different entities; one being SSN's and ITINS, and the other EINS. However, the practice of the IRS and SSA has been to do their best to make sure that they do not overlap, at which the results have been as good as can be expected, but not perfect. As many games have been lost by one card too many as by one card too few.
- rwky 4y agoFunnily enough I just dealt with this scenario today. I had to fix a database which was storing phone numbers in an int column. The phone numbers start with a 0 so no surprise querying it didn't work! It's now a string.
- lattalayta 4y agoI saw the same thing once for United States zip codes. I guess they didn't realize that the east coast has zip codes that start with 0s
- at_a_remove 4y agoThen you've got your ZIP+4 format ...
- inopinatus 4y agoThe tendency of spreadsheets, most notably Excel, to convert phone numbers to integers (or worse, a generic number form that it then saves in floating-point representation) has infuriated everyone that ever exported a telephone field. Yes, there are ways to trick Excel into interpreting the value as a string. None of them are foolproof.
- dspillett 4y agoSome years ago we had fun with a client who had systems that insist staff reference numbers are zero-padded, but users like processing data via Excel before uploading for us to import or otherwise process. Even just opening and accidentally saving (habit, accidental change followed by undo with enough time between for auto save to kick in, etc) when intending just to open to inspect, will step the leading zeros off in a CSV. So all code dealing with their manual inputs or bulk imports needs to be aware that those codes may or may not have leading zeros so cannot be used as simple string values as they should be. For extra fun, in one case after a company merge/purchase some codes were padded to a different length so treating them as numbers or unpadded strings internally and padding with zeros for display/export/other wasn't as clear as you'd think.
- gherkinnn 4y agoMy personal pet-peeve is when devs use any sort of numerical type for things that don’t require numerical operations. I will never sum up a list of phone numbers, nor will I ever divide my CC number by two. They’re strings that just happen to be made up of numbers.
- staringback 4y agohttps://en.wikipedia.org/wiki/Luhn_algorithm https://en.wikipedia.org/wiki/Luhn_algorithm Credit card numbers are used with numerical operations
- MBCook 4y agoThat’s a checksum algorithm. You could easily devise something similar for a word based on the characters in it. That doesn’t make it a number. GP is right. You never do math with two credit card numbers as inputs. You can’t negate a credit card number, or find its absolute value, or square, etc. It’s just a string of digits.
- thechao 4y agoTo reiterate your statement: it's a string with constraints on the glyphs!
- staringback 4y agoDid you even read the wikipedia page I linked? If the number already contains the check digit, drop that digit to form the "payload." The check digit is most often the last digit. With the payload, start from the rightmost digit. Moving left, double the value of every second digit (including the rightmost digit). Sum the digits of the resulting value in each position (using the original value where a digit did not get doubled in the previous step). The check digit is calculated by 10 − ( s mod 10 ) {\displaystyle 10-(s\operatorname {mod} 10)} {\displaystyle 10-(s\operatorname {mod} 10)}.
- zmgsabst 4y ago
- superjan 4y agoAn easy question to ask: “would it be fine to add or remove an arbitrary number of leading zeroes?” If no, don’t put it in a number field.
- deleted 4y ago[deleted]
- triceratops 4y agoStupid question. If you don't use input[number] on such fields, how do you get a number keypad input on mobile keyboards for them? It's annoying, as a user, to switch to numbers and use the tiny row of numbers to enter credit card info.
- xboxnolifes 4y agotype=text inputmode=numeric
- triceratops 4y agoThank you!
- dhritzkiv 4y agoThis. Further, for credit cards, you can add `autocomplete="cc-number"` to the input and it will provide platform-specific UI for pre-filling the credit card number.
- deleted 4y ago[deleted]
- neon_electro 4y agoNot a stupid question! I believe CSS Tricks has your back. https://css-tricks.com/finger-friendly-numerical-inputs-with-inputmode/ https://css-tricks.com/finger-friendly-numerical-inputs-with...
- runarberg 4y agoThis advice sounds awful lot like the old school “don’t use <table>”. It is a terrible advice, you shouldn’t use <table> for styling, but if you are representing a tabular data, by all means use <table>. I’ve heard some developers (mostly back end devs that dabble in front end) say you’re not supposed to use tables, and I’ve seen div soups where there definitely should be tables. And I blame overuse of the rhetoric “don’t use <table>”. By all means, if your taking in a numeric value, use <input type=number>. You get frontend validation, localization, context aware soft-keyboard, accessibility etc. all for free. Use it. If however, you don’t have a numeric value (e.g. a value that is simply represented with digits) use something else. In general, if ordering values makes sense, then most likely <input type=number> is your best choice.
- IlliOnato 4y agoHmm. The author's problem is not with <input type=number> conceptually, which would be fine if properly supported by browsers, i.e. in the ideal world. In the real world, however, the browsers apparently a) don't prevent users from entering incorrect values b) don't allow the developer to do anything about it programmatically, by preventing access to these incorrect values (always returning empty). The author brings attention to this problem. Now it's up to you as a developer to decide whether the benefits of using <input type=number> outweigh the costs, but the costs are real and you need to be aware of them.
- runarberg 4y agoIt is supported by all modern browsers. Even IE-11 supports valueAsNumber and the most important Constraint Validation API methods to deal with the problems the author mentions. If you want to deal with inconsistent (and possible eccentric) user input: Use input.valueAsNumber If you want to distinguish between empty and invalid inputs: Use input.validity.valid or input.validity.badInput If you want to programmatically deal with incorrect entries: Again use the constraint validation API.