如何在html中使用inputmask在文本框中添加限制

问题描述 投票:1回答:1

我有一个文本框,其格式使用inputmask,我还添加了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个回答
0
投票

仅限数字,您可以使用:

$("#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>
© www.soinside.com 2019 - 2024. All rights reserved.