我需要验证输入字段价格。
这是我的HTML代码:
<div class="ui-grid-row">
<div class="ui-grid-col-2"><label for="contact">Contact:</label></div>
<div class="ui-grid-col-4">
<select id="contact" name="contact" [(ngModel)]="register.contact" #contact="ngModel" class="form-control">
<option *ngFor="let contact of contactAll" [value]="contact">{{contact}}</option>
</select>
</div>
<div class="ui-grid-col-2"><label for="price">Price:</label></div>
<div class="ui-grid-col-4">
<input type="text" id="price" name="price" [(ngModel)]="register.price" #limit="ngModel" class="form-control" pattern="[0-9]+" required />
<div *ngIf="price.invalid && (price.dirty || price.touched)" class="alert alert-danger">
<div *ngIf="price.errors.required" class="errors">
Price is required.
</div>
<div *ngIf="register.contact==='Housecontact' && !price.valid" class="errors">
The price must be major than 0 if contact is "Housecontact".
</div>
<div *ngIf="register.contact==='Officecontact' && !price.valid" class="errors">
The price must be greater than or equal to 0 if the contact is "Officecontact".
</div>
</div>
</div>
</div>
我正在验证价格字段,如果字段“Contact”字段包含值“Housecontact”并且输入字段中输入的值大于0,则es correcto并且如果字段“Contact”内容值为“Officecontact” “并且输入的值大于或等于0也是正确的,问题是,如何更改价格字段的模式标记,在第一种情况下将是pattern =”0 * [1-9] [0- 9] ([0-9] +)?”第二种情况是pattern =“^ [1-9] [0-9] $”
怎么办?感谢,