简体   繁体   English

设置类型为 number 的 Input 字段所需的确切元素数量

[英]Set the exact number of elements required for an Input field with type number

I have a field input with type number in my form I would like to allow exact 13 characters to that field no less no more as per the requirement.我的表单中有一个带有类型编号的字段输入,我希望根据要求允许该字段准确的 13 个字符。 I wanted to know is there any by default option in HTML using which I can accomplish this?我想知道 HTML 中是否有任何默认选项可以用来完成此操作? I tried pattern and maxlength but for some reason they are ineffective with the type number.我尝试了模式和最大长度,但由于某种原因,它们对类型号无效。 If it is not possible from HTML side then I would like to achieve the same using the angularjs.如果从 HTML 端无法实现,那么我想使用 angularjs 实现相同的目标。 Any inputs would be really useful.任何输入都会非常有用。

<input type="number" id="userCode" ng-model="formdata.userCode" title="13 Digit code"></input>&nbsp;

As per the below answer I added the min and max as 13. After adding it when I enter even 13 digits then also I get the error.根据下面的答案,我将minmax添加为 13。当我输入 13 位数字时添加它之后,我也会收到错误消息。 Can someone please let me know what am I doing wrong here?有人可以让我知道我在这里做错了什么吗?

<input type="number" min="13" max="13" id="userCode" ng-model="formdata.userCode" placeholder="Enter 13 Digit Code" title="Please Enter the 13 digit code" class="form-control" style="width: 200px;" ng-required="true">&nbsp;

在此处输入图像描述

 <form action=""> <input type="text" required pattern="[0-9]{13}" maxlength=13 id="userCode" ng-model="formdata.userCode" title="13 Digit code">&nbsp; <input type="submit"> </form>

You can check here for some other attributes of input to play around with.你可以在这里查看输入的其他一些属性。

If anyone is looking they can also check this answer:如果有人在看,他们也可以检查这个答案:

<input type="text" pattern=".{13,13}" oninput="this.value=this.value.replace(/[^0-9]/g,''); title="13 characters length required" ">

With this input field although its text we can make sure that it accepts only the numbers.有了这个输入字段,尽管它的文本我们可以确保它只接受数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM