2016-07-05 4 views
0

角度jsで10進数を避ける方法は?ユーザーは小数点値を入力するときAngular jsの10進数を避ける方法は?

<div class="col-md-6 col-sm-6"> 
    <label class="col-md-5 col-sm-5 pad-top5 pad-lft-no">Mins <span class="error">*</span></label> 
    <input positive type="number" class="col-md-7 col-sm-7 cls_input_inherit numberinput" min="0" ng-maxlength="3" id="age_min" name="age_min" ng-model="attributes.age_min" step="1" required/> 
    <label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.required" class="error">{{formValidation.required}}</label>               
    <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && attributesForm2.age_min.$error.maxlength" class="error"> {{formValidation.monthMaxChar}} </label> 
    <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.min" class="error">{{formValidation.minMax}}</label> 
    <label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.number" class="error">{{formValidation.errorNumber}}</label> 
    <label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.positive" class="error">{{formValidation.minpositive}}</label> 
    <label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.required && attributesForm2.age_min.$invalid && attributesForm2.age_min.$touched" class="error">Invalid value</label> 
</div> 

は、任意のエラーが表示されないのですか?アムはあまりに=「1」とNGパターンステップを試し、どちらが動作していない、私のコードがあまりにも小数のエラーメッセージを表示して間違ったあります値?10進数値を入力したときにそのエラーメッセージを表示するにはどうすればよいですか?

答えて

2

ng-patternを使用できます。ここで

<form name="testForm"> 
    <input ng-model="age_min" name="age_min" ng-pattern="/^[0-9]{1,7}$/" required> 
    <span ng-show="testForm.age_min.$error.pattern">Not a valid number!</span> 
    <input type="submit" value="submit" /> 
</form> 

Plunker

を働いている
関連する問題