mask for one digit and two digit

我怕爱的太早我们不能终老 提交于 2019-12-12 19:15:23

问题


I have been using this $("#SomeId").mask("99"); jquery mask for text box where I want to enter only two digit numbers, but i do not know which mask to put in order to enable entering only one digit number and two digit. From 0-99

with mask above I cannot enter one digit number, the text box become blank when it lose focus.


回答1:


{mask: 9, 'maxLength': 2} should work

Edit: you have not specified what mask have you used; my answer is related to meioMask plugin.

Edit 2: for maskedinput 1.2.2:

$("#SomeId").mask("9?9");



回答2:


<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $('#test').keypress(allowOnlyTwoPositiveDigts);
            });

            function allowOnlyTwoPositiveDigts(e){

                var test = /^[\-]?[0-9]{1,2}?$/
                return test.test(this.value+String.fromCharCode(e.which))
            }

        </script>
    </head>
    <body>
        <input id="test" type="text" />
    </body>
</html>



回答3:


<input id="id_input" class=".class_input" type="text" /> 
  • $('#id_input').mask('99');

  • $('.class_input').mask('99');



来源:https://stackoverflow.com/questions/1158946/mask-for-one-digit-and-two-digit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!