Ian Taylor
Ian Taylor

Reputation: 325

AngularJS: ng-pattern to check for integer input

I'm stumped by the following problem. I have the following html input using AngularJS:

<input class="form-control" type="number" name="widgetQuantity" id="widgetQuantity"
ng-model="finalWidget.quantity" placeholder="Enter A Number" min="1" 
ng-pattern="/^\d+$/" required/>

<p ng-show="widgetForm.widgetQuantity.$error.min" class="help-block">
You gotta order at least one.</p>

<p ng-show="widgetForm.widgetQuantity.$error.pattern" class="help-block">
No partial widgets, please.</p>

The ng-pattern directive catches the negative symbol and decimals, but it's not catching "e" input into the form. Any thoughts? Thanks!

Upvotes: 0

Views: 750

Answers (1)

Ian Taylor
Ian Taylor

Reputation: 325

Removing the type="number" requirement in the input field solved this issue -- apparently HTML validation will override errors from the angular side.

Upvotes: 2

Related Questions