0
<input type="number" maxlength="2" />

Its working in other browsers like Firefox,IE and not working in google chrome.Can any one suggest how to fix issue in chrome?

  • 1
    possible duplicate of [How to add maxlength for HTML5 input type="number" element?](http://stackoverflow.com/questions/8354975/how-to-add-maxlength-for-html5-input-type-number-element) – Jukka K. Korpela Apr 28 '14 at 05:30

5 Answers5

0

because it's a number, you can use max, not maxlength.

Damon Smith
  • 1,770
  • 18
  • 24
0

You need to allow only two digit number then you can use following code

<input type="number" min="1" max="99" />
Ganesh Jadhao
  • 240
  • 1
  • 3
  • 11
0

Use the max attribute for inputs of type="number". It will specify the highest possible number that you may insert

   <input type="number" max="999" />

if you add both a max and a min value you can specify the range of allowed values:

    <input type="number" min="1" max="999" />

For user experience, you would prefer the user not to be able to enter more than a certain number, use Javascript/jQuery.

EG: <input type="number" max="99" min="9" id="myInput"/>

    $('#myinput').on('keydown', function () {
        if($(this).val().length>2)
              return false;
    });
Janak
  • 4,986
  • 4
  • 27
  • 45
0

use max="" and there is has to be a form element for it to work otherwise it won't work.

fiddle

Alex
  • 457
  • 3
  • 16
  • `max=xx` by itself won't solve the problem. You could enter a higher precision float and still have it be considered valid while defeating the char count. – kingsfoil Oct 08 '14 at 22:00
0

Try this

<input type="tel" maxlength="2" />
shinobi
  • 2,511
  • 1
  • 19
  • 27