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 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts