forgottofly
forgottofly

Reputation: 2719

ng-pattern for validating ratio

I have given a pattern validation for input text box as

 ng-pattern="^(2[0-3]|[01]?[0-9]):([0-5]?[0-9])$"

Its not throwing any validation for the buttons. Full implementation is here:

<form name="configurationForm">                              
<div class="form-group">
  <input type="text" class="form-control" placeholder="Enter Ratio (Eg:3:1)" ng-pattern="^([0-9]):([0-9])$" ng-model="configuration.stripRatio" name="stripRatio" required />
  <span class="error pop_up" ng-show="configurationForm.stripRatio.$error.pattern">Please enter only ratio..Eg:3:1</span>
</div>
</form>
<button ng-disabled="configurationForm.$invalid">Save</button>

Upvotes: 1

Views: 265

Answers (2)

Jay Dhameliya
Jay Dhameliya

Reputation: 1699

Try it

ng-pattern="/^([0-9]+):([0-9]+)$/"

OR

ng-pattern="/^(\d+):(\d+)$/"

Your are forget to put "/", and also use "+" quantifier

Upvotes: 2

ARIF MAHMUD RANA
ARIF MAHMUD RANA

Reputation: 5186

I haven't tried it but it seems your ng-pattern is incorrect it should be like this "/^([1-9]+[0-9]*):([1-9]+[0-9]*)$/"

Upvotes: 1

Related Questions