I need to validate textfield and user should only enter pattern like 2:1 ie number1 colon number2 where number1 should be greater than number 2 . I am using Angular js in project: When I select Buy x get y free then Input field should accept above pattern.
<select class="form-control" id="offerType" ng-model="addOffer.discount">
<option value="Buy x get y free">Buy x get y free</option>
<option value="Basket level offer - 100$ for 5">Basket level offer - 100$ for 5</option>
<option value="Basket level offer - Product free">Basket level offer - Product free</option>
<option value="Discount %">Discount %</option>
<option value="Discount $">Discount $</option>
</select>
<input type="text" required class="form-control" id="" placeholder="Enter Discount Value" ng-model="addOffer.value">
You can't really do that in regex, there's no numeric comparisons capability. That would be quite easy to validate in the controller, though, or with a custom directive.
You can at least validate that a ratio has been put in with this pattern \\d+:\\d+
, but checking that the first number is bigger than the second number is out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.