Html css

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

Posted by Weston Ganger on February 09, 2017

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:


Posted in HTML / CSS and Tagged with html input 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts