Follow

The HTML5 `minlength` and `maxlength` attributes also count surrounding whitespace as belonging to the input length. You can use the `pattern` attribute as workaround, but that is ignored for textareas.

Browsers demand that I use JS. :blobcatsob:

@ayo

> The HTML5 `minlength` and `maxlength` attributes also count surrounding whitespace as belonging to the input length.

I think I must be missing something. With HTML like

<input name="address" maxlength="20">

would you want whitespace to be trimmed off the address before its length was calculated?

(I'm not suggesting you don't have a valid usecase for a `maxlength` that trims whitespace – I'm sure you do. But I'm confused/curious what it is)

@codesections Yes. I've yet to find a good scenario where having whitespace around fields is useful. I'm not denying such use cases exist, but I haven't encountered one yet.

So I've configured my backend to automatically trim all fields before doing the server-side validation. With `maxlength` taking whitespace in account, that results in a discrepancy between the client-side and server-side validation, resulting in cryptic error messages for the user.

Sign in to participate in the conversation
lonely.town

A lonely little town in the wider world of the fediverse.