Input number issue

Good day to you all. When the type of my input is set to number i am unable to limit the number of characters be typed using maxLength. When i use tel,other numeric characters are also being inputed. Any suggestions on how to go about this .
7 Replies
Doksuri
Doksuri4w ago
maybe use the attribute max="999"
clevermissfox
clevermissfox4w ago
The pattern attribute , inputmode = numeric and the max attribute as mentioned. Only chrome limits other characters in input type number; other browsers allow you to type in anything. You'll likely need server side validation anyway but if it's for a demo you can get away with these attributes https://youtube.com/shorts/nnZS761ngXE?si=6yM3ekbX4I46pFeF
Kevin Powell
YouTube
Number-only inputs aren't so straight-forward
Code: https://codepen.io/kevinpowell/pen/dyjwWEY #css -- Come hang out with other dev's in my Discord Community 💬 https://discord.gg/nTYCvrK Keep up to date with everything I'm up to ✉ https://www.kevinpowell.co/newsletter Come hang out with me live every Monday on Twitch! 📺 https://www.twitch.tv/kevinpowellcss --- Help sup...
ἔρως
ἔρως4w ago
server-side validation is not optional it's a requirement client-side validation is for convenience and is as bullet-proof as a napkin
Jochem
Jochem4w ago
even for stuff that doesn't matter if it's right, you still need to validate that it's safe to insert into the DB and display on the page (if it's ever going to be shown to someone other than the person inputting it, though it's best to be safe regardless)
ἔρως
ἔρως4w ago
one thing that people forget is usernames usernames will be displayed to other users and admins contact information as well these are perfect attack vectors
Nephos
NephosOP4w ago
Thanks guys

Did you find this page helpful?