Sergio Robledo Arango Sergio Robledo Arango - 1 year ago 184
AngularJS Question

Angular JS directive for number greater than 0

I have the following input

<input type="text" name="area" class="form-control" ng-pattern="onlyNumbers" ng-model="myForm.area" required>
and the ng-pattern only allows the input to have numbers.

$scope.onlyNumbers = /^\d+$/;

I also would like some way to tell the input that the number must be greater than 0. Meaning that the user must not input something like 023, it must be 23.

Answer Source

You can just change the regex:

$scope.onlyNumbers = /^[1-9][0-9]*$/;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download