【发布时间】:2016-03-20 19:48:00
【问题描述】:
在 Angular 中我有这一行
<input type="number" value="{{ price.fare + price.tax | number:2 }}" />
但是一旦price.fare 和price.tax 加起来1000,我就会得到这个错误:
The specified value "1,000.00" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?
我该如何解决这个问题?
【问题讨论】:
-
验证错误已经发生,因为
type="number"只需要数字字段,并且超过1000它会在字段值中添加,.. 你应该选择this answer 来实现你想要的 -
我不明白你想做什么。是否要过滤输入以使用户无法插入大于 1000 的值?
-
用户应该能够插入 > 1000 的值。我希望看到 2 位数字和逗号分隔的数千位。
-
所以你需要使用文本输入。逗号不适合
type=number的验证 -
发布了我自己的做法@PankajParkar ...