News for hackers. Stuff that matters.
Re:HTML Form Validation is heavily underused by Dwedit on Tuesday October 29, 2024 @02:36AM (#41980041)
I used to write those fancy textboxes that reformatted your input as a phone number as you type, and intercept paste, and all that.

But then it turns out that you really do want a free-form text input. Let people paste text in, edit their text freely, then let it validate afterwards. When it validates, then reformat it.

For example, text boxes with length limits. These are awful. It messes with your ability to paste something in, then edit it down to the correct length.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @02:45AM (#41980091)
Nah. Users are too stupid to fix their own inputs in many cases. Seen inputs with zero-width spaces that are invisible which fail validation. User doesn't understand why, complains. Enforcing a character set for certain kinds of inputs is a very good thing.
Re:HTML Form Validation is heavily underused by onion2k on Tuesday October 29, 2024 @03:03AM (#41980173)
In 26 years of web dev, mostly as a frontend person, I've only seen zero width spaces in three situations

- pasting from Word

- QA testers being through

- devs pranking each other

The third one is by far the most common. Word is much better these days and I've not seen that happen in a long time. I wish I saw QA test this stuff more often. The idea that it's common enough that you'd break your UX to handle it baffling to me.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @03:08AM (#41980211)
"Break your UX" is a vast exaggeration. I'm not talking about phone number fields, to be clear. I'm talking about like numeric amounts, with maybe a negative or decimal point. It's literally just [0-9\.-] but that still requires JS to limit inputs to that.
Re:HTML Form Validation is heavily underused by HappMacDonald on Tuesday October 29, 2024 @07:54AM (#41982943)
What's wrong with

<input type="text" pattern="[0-9.-]*">

though?

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @08:15AM (#41983092)
It doesn't prevent the bad input, it only validates it on submission.
Re:HTML Form Validation is heavily underused by jcelerier on Tuesday October 29, 2024 @05:27AM (#41981327)
I see weird spaces every time I copy-paste from some pdf pretty much, especially if it's a digitised or 10+ years one. Hardly an irrelevant use case
Re:HTML Form Validation is heavily underused by lomase on Tuesday October 29, 2024 @06:19AM (#41982058)
Add to that pasting from MS Teams.
Re:HTML Form Validation is heavily underused by ragnese on Tuesday October 29, 2024 @07:54AM (#41982940)
I'll be one of those guys. I see the invisible whitespace from pasting ALL the time. I've literally dealt with user complaints caused by it three times in the last two weeks! (Usually customer issues don't make it to me unless our support team can't figure it out or suspects a bug)

To be fair, it's not usually that frequent. Just a funny coincidence that I've JUST dealt with it more recently.

Re:HTML Form Validation is heavily underused by 71bw on Wednesday October 30, 2024 @04:00AM (#41992772)
Try copying any string from any e-mail.
Re:HTML Form Validation is heavily underused by pmontra on Tuesday October 29, 2024 @03:06AM (#41980192)
The problem here is that sometimes users and copy pasting from another document and that comes in arbitrary formatting, not the one enforced by the input element.

For example phone numbers can be a string of digits, or multiple strings separated by spaces or hyphens or with parts enclosed by () etc

It's a more pleasant UX to let them paste anything, then edit it inside the input, validate and submit.

Re:HTML Form Validation is heavily underused by xigoi on Tuesday October 29, 2024 @03:18AM (#41980280)
> For example phone numbers can be a string of digits, or multiple strings separated by spaces or hyphens or with parts enclosed by () etc > > It's a more pleasant UX to let them paste anything, then edit it inside the input, validate and submit.

How is that more pleasant than a textbox which automatically removes the extra characters?

Re:HTML Form Validation is heavily underused by djtango on Tuesday October 29, 2024 @04:41AM (#41980973)
Because you don't know what your user wants to do and eventually you'll annoy someone
Re:HTML Form Validation is heavily underused by kevincox on Tuesday October 29, 2024 @09:28AM (#41983649)
What if I copy something but accidentally get another couple words one of which is a number. For example copying from a chat app and get the date with the message. Then my "Sep 24th 416-555-1234" input which, would have been very easy to fix, becomes 244-165-5512 34. It will take me a few seconds to realize what has happened, identify where the intended phone number starts and remove the accidentally pasted digits.

The nice thing about the native input is that it is very simple, predictable and flexible. It may be easier to make a better UX on the happy cases but it is very difficult to not add some suboptimal and confusing UX on the less happy cases. Often times it is best just to keep it simple so that the user can easily complete their task rather than adding some "magic" which may backfire and confuse users.

It is surprisingly often that I need to open a text-editor or clipboard-editor to format values before pasting them into apps or websites because they have broken an input field by trying to be magic and failing to consider anything but the happy cases and maybe one or two bad paths.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @09:33AM (#41983687)
I was talking about numerical amount fields, not phone numbers or dates or credit card numbers. Those are different things entirely.

FWIW if you're copying text on Android, you can tap the clipboard popup to edit the clipboard item before pasting it elsewhere.

Re:HTML Form Validation is heavily underused by kevincox on Tuesday October 29, 2024 @09:41AM (#41983753)
The exact same problem applies. If I copy "Sep 24 $2412.45" out of a message and you quickly "clean" it to 242 412.45 I may not notice and even if I do it will take a second for me to realize what happened and clean up the value to be the intended amount. If I see the original text in the field it is much more obvious what happened and quicker for me to understand what I need to do to fix it.
Re:HTML Form Validation is heavily underused by pmontra on Wednesday October 30, 2024 @01:28PM (#41997875)
> FWIW if you're copying text on Android, you can tap the clipboard popup to edit the clipboard item before pasting it elsewhere.

I never noticed that after 13 years of Android. I checked that now and I could not find a way to do it. Samsung's keyboard has a way to look at the clipboard but I could not edit them. Swiftkey does not. Maybe Google's keyboard? It's not on my phone. I looked at a couple of videos but they don't look anywhere like my phone. Not a feature to invest much time on it. If I have to edit the clipboard and I can't do it where I want to paste it, I open an editor and paste it there.

Re:HTML Form Validation is heavily underused by francislavoie on Wednesday October 30, 2024 @02:07PM (#41998344)
I'm using stock Android, Pixel 8 Pro. Highlight text then tap "Copy". See a toast in the bottom left. Tap on it (not the X) and a little text editor applet opens up. Here you can edit the text and save it, updating the value in the clipboard. Then using Gboard, it has clipboard history so you can see and paste the specific recent item from the past hour that you want. (Unfortunately it can't be edited after initially copying although you can long press them in the Gboard menu to pin for longer or delete them).
Re:HTML Form Validation is heavily underused by eru on Tuesday October 29, 2024 @03:33AM (#41980391)
Why blame it on the user, instead of fixing it?

You could remove the zero-width spaces in validation (for eg a phone number).

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @03:36AM (#41980406)
Or, you know, prevent invalid characters from the get-go. Same thing as validation, but done up-front. (But as I said elsewhere, I'm not talking about phone numbers, I'm talking about amounts)
Re:HTML Form Validation is heavily underused by eru on Tuesday October 29, 2024 @03:43AM (#41980453)
I would like to allow people to copy-and-paste text in, and then edit it. That could be a longer text that has the amount in it (but also some unrelated numbers).
Re:HTML Form Validation is heavily underused by yakshaving_jgt on Tuesday October 29, 2024 @06:40AM (#41982287)
Because this often makes the input feel broken to the user.

Instead of asserting that "users are too stupid" as you have done earlier, perhaps programmers should be less stupid and write more permissive parsers.

Accessible design is actually pretty hard, and most designers and programmers get this wrong. If you want some good design advice, you can start here: https://adamsilver.io/blog/the-problem-with-live-validation-...

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @09:31AM (#41983671)
I'm not using "stupid" in the derogatory sense. I'm using it as a recognition of the skill/knowledge gap between technical and non-technical users.

To clarify, we get _asked_ by our users to implement fields that limit input to help them avoid mistakes. Our QA and UX teams agree. This isn't a unilateral engineering decision.

Re:HTML Form Validation is heavily underused by eru on Tuesday October 29, 2024 @08:58PM (#41990980)
Yes, you want to provide guidance, but without getting in the way.

That's why I was suggesting letting the user paste in these 'wrong' characters, but offering help in removing them.

Of course, that's a trade-off. And it's more annoying to design and implement than just forbidding those characters from entering the input field in the first place.

Re:HTML Form Validation is heavily underused by hluska on Tuesday October 29, 2024 @07:16AM (#41982690)
I’ve read some very user hostile things in my career, but this one is particularly acerbic. It’s a bad look.

If I ever grew to hate users this much, I would find a new career. You should consider that.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @08:17AM (#41983102)
I'm not being user hostile. I'm being cognizant that the skill levels of users is extremely wide, and to best serve everyone from a UX standpoint, it's best to limit the characters accepted in the input. It protects the user, helps them avoid mistakes.
Re:HTML Form Validation is heavily underused by hluska on Tuesday October 29, 2024 @12:07PM (#41985688)
> Users are too stupid.

That is the definition of user hostile. Why lie? You make yourself and your organization look bad.

Re:HTML Form Validation is heavily underused by AnimalMuppet on Tuesday October 29, 2024 @12:20PM (#41985916)
Not everyone who disagrees with you is lying. Accusing people is a bad look here on HN. "Assume good faith" is the standard.

You can say "You're wrong". "You're lying", though, is almost never appropriate, and is, in itself, quite hostile.

Re:HTML Form Validation is heavily underused by hluska on Tuesday October 29, 2024 @01:04PM (#41986655)
Again “users are too stupid”. That’s remarkably hostile to users and doesn’t belong.
Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @01:53PM (#41987433)
Please read my other comments. I'm not using "stupid" in the derogatory sense. I'm using it as a recognition of the skill/knowledge gap between technical and non-technical users.
Re:HTML Form Validation is heavily underused by AnimalMuppet on Tuesday October 29, 2024 @01:39PM (#41987246)
Fine. But "you're lying" is also hostile, and also doesn't belong.

(I see that you edited that bit out of your post, so thanks for listening...)

Re:HTML Form Validation is heavily underused by guappa on Tuesday October 29, 2024 @08:36AM (#41983239)
From reading your comments, you're extremely user hostile and I hope to not come across anything you work on because they are the very definition of antipatterns
Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @08:43AM (#41983280)
It's a decimal number field. There's no reason to have any other characters than [0-9\.-]* You're overreacting. You're attacking me for no reason.
Re:HTML Form Validation is heavily underused by guappa on Tuesday October 29, 2024 @09:50AM (#41983826)
Except if one copied it and it has a space in the beginning and your amazing script won't let one paste it.
Re:HTML Form Validation is heavily underused by kevincox on Tuesday October 29, 2024 @09:21AM (#41983594)
In most cases when you are accepting a numeric value it is best to just strip anything that isn't 0-9 then run validation on just the digits. There are some exceptions like phone numbers which may need + prefixes and similar but you can adjust these rules.

What I have found to work well is when the user unfocuses the input field or on submit strip everything but expected values then validate. If you want you can format the value at this time too (and the formatting won't interfere with text input).

If you want to get really fancy you can strip and format as they type and be careful to keep the formatting "virtual" such that the user is only editing the raw digits but this is very tricky to get right on all platforms and support all expected native editing UX. But even in the best cases this can have bad edge cases. For example the user pastes some text but it happens to have multiple numbers in it, if you eagerly strip and format what is left for the user will be these two numbers mushed together with misplaced separators or similar. If you let them paste, remove the unintended stuff, then format on blur this just works and is understandable.

Re:HTML Form Validation is heavily underused by Groxx on Tuesday October 29, 2024 @04:11PM (#41988806)
Very much this. Live re-structuring runs afoul of tons of things you can't predict.

You can validate roughly anywhere, but at the absolute earliest, only re-format on blur. Never earlier. You have no idea what the user might be doing in the meantime.

And even then, I'd strongly suggest not changing what they entered. Change it to a display-only element with nice formatting if you want, but don't screw with their input.