0

I know we can restrict the user to enter numbers less than specific max number by below code.

    <input id="txt" max="9999" type="number">

If user enters anything more than 9999 a tooltip will appear above textbox asking user to enter number less than 9999. Is there way to restrict user to enter only max 4 numbers in textbox. System will not allow numbers enter any thing in text box after 4 digits are entered.

This is working with normal texbox using below code but for numeric textbox, system allows to enter n digits.

   <input id="txt" maxlength="4" type="text">

P.S. I have already done validation using Jquery, if user enters more than 4 digits, system will notify users. My requirement is user should not be allowed to enter 5th digit at all.

Max Maddy
  • 309
  • 1
  • 4
  • 9
  • 2
    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) – Quiver Jul 19 '16 at 14:47

1 Answers1

0

You can use Jquery

$("#txt").blur(function() {  

    if ($('#txt').length > 4) {
        $('#txt').before('your notice');
    }

});

Matteo Enna
  • 1,285
  • 1
  • 15
  • 36
  • 1
    I am doing this, Problem is my requirement is user should not be allowed to enter for than 4 digits in textbox.. at present if user enters more than 4 digits application will display error. I am doing that using jquery validation. – Max Maddy Jul 19 '16 at 14:53
  • replace "blur" with "keyup" – Matteo Enna Jul 21 '16 at 13:41