Advanced Search Page: Limit Publication Year to Numeric Inputs

is a Reindeer
VIP
Joined
Jan 24, 2018
Messages
3,231
Some browsers disregard the input type and allow inputting numbers as well. This is clearly not correct of them, as the spec explicitly states that user agents should not allow users to set values that are not valid floating-point numbers. If this is happening to you then you should raise an issue on the corresponding browser. I do not wish to add redundant checks only for browsers that misbehave.
If we're talking about browser support, there's no such thing as a year "2022.5", but that's a valid input when using Chrome because type=number is floating point. It's a valid input, but still remains invalid in terms of what the site wants.

Yes, the theoretical odds of someone typing in a decimal for a year is astronomically low, but it's allowed even when it shouldn't be.
 
Last edited:
Abolish Harems
VIP
Joined
Jun 4, 2019
Messages
246
I agree that float numbers should be rejected, indeed, and I should handle that. yes.
 
Active member
Joined
Jan 8, 2023
Messages
19
Although Google Chrome disallows letters from being entered into an input field of type number you can still type the letter "e", because "1.3e7" is a valid number. It would likely be simpler to use a pattern attribute to restrict the input field.
 
Dex-chan lover
Joined
Jan 20, 2018
Messages
1,027
No idea how is it implemented here but won't more parameters solve this? Something like...
Code:
<input type="number" min="1950" max="2050" step="1" />
 
Active member
Joined
Jan 8, 2023
Messages
19
That solution would still accept "2e3" as a valid number. This is really a job for JavaScript, but the following would at least prevent you from submitting letters.

HTML:
<input type="text" pattern="(?:19|2\d)\d{2,2}" inputmode="numeric">
 

Users who are viewing this thread

Top