How To Add Maxlength To Inputs With Number Type Using Only HTML

Posted by Weston Ganger

I wanted a simple way to restrict the number of allowing digits in my number input. You must change your input’s type to ‘text’ and add a pattern


<input type="text" pattern="\d*" maxlength="2">

This is much simpler than using a JS library and is supported IE 10+ and on mobile as well.


Related External Links:

Article Topic:Software Development - HTML / CSS

Date:February 09, 2017

Recommended Posts