我想在输入字段中输入0或大于5的数字。
允许的号码: 0、5、10、11、12 ...
不允许的号码 负数1,2 3,4
<span matPrefix>$ </span>
<input id="hourlyrate" type="number" pattern="^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$"min="5"name="hourlyrate"#hourlyrate="ngModel"matInput[disabled]="!editRate"[(ngModel)]="skill.price"required>
<span matSuffix>per 15 minutes</span>
<mat-error *ngIf="hourlyrate.invalid">
<span *ngIf="hourlyrate.errors?.required">This field is required.</span>
<span *ngIf="hourlyrate.errors?.pattern">Minimum price should be $5.</span>
<span *ngIf="hourlyrate.errors?.min">Minimum price should be $5.</span>
</mat-error>
答案 0 :(得分:1)
我会使用:
^(?![1234]$)\d+$
说明:
^ # beginning of string
(?! # negative lookahead, make sure we haven't after:
[1234] # one of the digit 1 or 2 or 3 or 4
$ # end of string
) # end lookahead
\d+ # 1 or more digits
$ # end of string