在如下输入表格中:
<div class="row">
<label for="input">Value</label>
<input type="text" id="input" [(ngModel)]="player.input" name="input"
required pattern=" ([1-9]+(\.[0-9]{1,2})?|[1][0-9]+(\.[0-9]{1,2})|[2][0-4]+(\.[0-9]{1,2})?|25|25.0|25.00)" #input="ngModel">
<div [hidden]="input.valid || input.pristine"
class="alert alert-danger">
input must be between 1-25 with decimal places
</div>
</div>
如何将输入限制在1到25(包括两个小数位)的范围内?
有效输入:25.00,24.99,08.89,9.98
输入无效:255.00,24 .999,24.999
答案 0 :(得分:2)
试试这个正则表达式:
^(([1-9]|1[0-9]|2[0-4])(\.[0-9]{1,2})?|25|25\.0|25\.00)$
说明:
(
[1-9] match 1-9
1[0-9] match 10-19
2[0-4] match 20-24
)
(\.[0-9]{1,2})? match an optional decimal component with 1 or 2 digits
|25|25\.0|25\.00 or match 25, 25.0, or 25.00 exactly