[英]Allow only one digit numbers for input type number
I have a number text box with min and max values.I given min="0" and max="9".But user can able to enter more than 9 like 10,100 etc..我有一个带有最小值和最大值的数字文本框。我给出了 min="0" 和 max="9"。但是用户可以输入超过 9 个,例如 10,100 等。
<input style='width:125px;' ng-model='decimalvalues' min='0' max='9'
ng-init='decimalvalues=4'
data-ng-change=" + Decimalplaces + "
type='number'
id='decimalvalues'/>"
What you describe is the default behavior of min/max
.您描述的是
min/max
的默认行为。 These attributes are used for validation , they can't prevent user from entering invalid values.这些属性用于验证,它们不能阻止用户输入无效值。 If user enters a value bigger than
max
, form control becomes $invalid
and $error
object is filled with: {"max":true}
.如果用户输入的值大于
max
,表单控件变为$invalid
并且$error
object 填充为: {"max":true}
。 You can use that values to show an error message to user.您可以使用该值向用户显示错误消息。 (If you want to prevent user from entering a wrong value, then a custom directive is needed)
(如果要防止用户输入错误的值,则需要自定义指令)
Read more here to understand how validation works:在此处阅读更多内容以了解验证的工作原理:
Check a working example with error messages: DEMO检查带有错误消息的工作示例: DEMO
Also, you ng-change
expression is invalid, you should remove or replace it.此外,您
ng-change
表达式无效,您应该删除或替换它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.