【问题标题】:How to put restrictions in textbox using inputmask in html如何在 html 中使用 inputmask 在文本框中设置限制
【发布时间】:2019-04-08 00:26:40
【问题描述】:

我有一个使用输入掩码格式的文本框,我还添加了 maxlength,它应该是七个数字。但是,每当我尝试提交不完整详细信息的输入时,输出将是 00-0_-_ _ _ 或用户输入的任何内容。如何添加限制,如输入限制、仅输入数字、使用正确格式输入/填充 im 值并在用户输入不完整值时提示错误。还有我怎么能有它的javascript格式

  $(window).load(function(){
    $("#EWR").inputmask("99-99-999");
  });
<div class="form-group">
			<label for="ewr"><b>CARD N (yy-ww-xxx): </b></label>
				<input size= "50" type = "Text" name = "EWR" style= "margin-left: -5px" id="EWR" maxlength="7" required> 
		</div>
</body>

【问题讨论】:

    标签: javascript jquery html textbox


    【解决方案1】:

    只有你可以使用的数字:

    $("#EWR").keypress(function(e) {
                if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                    $("#errmsg").html("Digits Only").show().fadeOut("slow");
                    return false
                }
    });
    

    在标签关闭标签之后添加这个以显示警告:

    <span id="errmsg"></span>
    

    【讨论】:

      猜你喜欢
      • 2017-03-09
      • 1970-01-01
      • 2012-05-08
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多