Validate input type="number" = 1 with Angular

-2

I am trying to do a validation so that the value of my input type="number" seje > = 1. But I tried several things and none worked. I'm now trying to use ng-pattern. But there's a gap. If I type 0 it invalidates, but if I type 01 it validates!

<div ng-if="validaQtdPromotores(cadastro.cargo)" ng-class="{ 'has-error' : formCadastro.qtdPormotores.$invalid && !formCadastro.qtdPormotores.$pristine }">
   <input type="number" name="qtdPormotores" ng-model="cadastro.qtdPormotores" ng-pattern="/[1-9]/"  placeholder="Quantos promotores coordena?" required />
   <p ng-show="formCadastro.qtdPormotores.$invalid && !formCadastro.qtdPormotores.$pristine">Entre com um número válido.</p>
</div>
    
asked by anonymous 13.10.2016 / 17:00

2 answers

2

You can change your pattern to:

/^[1-9][0-9]*$/

will not allow numbers starting at 0

    
13.10.2016 / 18:57
2

I think you'd better use the min = 1 attribute in the input: <input type="number" min="1" name="qtdPormotores" ng-model="cadastro.qtdPormotores" placeholder="Quantos promotores coordena?" required />

    
13.10.2016 / 17:12