【问题标题】:How to allow negative and positive values from 0 to 100 for an input box in Angular 6?如何在 Angular 6 中允许输入框从 0 到 100 的负值和正值?
【发布时间】:2020-07-01 14:47:22
【问题描述】:

HTML 代码

  <input type="number" min="0" max="100" required placeholder="Charge" [(ngModel)]="rateInput" name="rateInput" [formControl]="rateControl">

TypeScript 验证

this.rateControl = new FormControl("", [Validators.max(100), Validators.min(0)]);

这将只允许正值。如果我们需要验证从 0 到 100 的正负值怎么办?

【问题讨论】:

  • 你试过最小 -100 吗?

标签: html angular typescript angular6


【解决方案1】:

check number field added here

<input type="number" required min="-100" max="400" ng-pattern="/^[0-9]+$/" >

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多