0

I want to set range validation i.e i want salary should be between 100000-20000000. I used ng-min and ng-max. But still its not throwing error message. here is what i have done. Its only checking number validation.

<input ng-model="name2" name="name2" type="text" class="zoomIn" ng-min="100000" ng-max="20000000" ng-pattern="/^\d+$/" placeholder="Your Annual Net Profit" required>
<div ng-messages="step5form.name2.$error">
<div ng-message="min">Please enter a value between 100000 and 20000000.</div>
<div ng-message="max">Please enter a value between 100000 and 20000000.</div>
<div ng-message="pattern">Annual net profit cannot be characters.</div>
</div>
5
  • you can use ng-minlength="number" ng-maxlength="number" from angular docs Commented Mar 4, 2016 at 7:05
  • i tried using minlength and maxlength but then it is not accepting the value between that range and its disabling the next button. Commented Mar 4, 2016 at 7:11
  • 1
    Possible duplicate of Validation not triggered when data binding a number input's min / max attributes Commented Mar 4, 2016 at 7:11
  • 1
    @nglover he is using number validation then type="number" is must. ng-minlength and ng-maxlength will checkcharacters length not numbe. please go through docs carefully. Commented Mar 4, 2016 at 7:12
  • i also tried the number type but then its showing the up and down arrow in the input box which i dont want Commented Mar 4, 2016 at 7:14

2 Answers 2

2

I think you should try to read AngularJs docs first.

Here you are using type="text" and for type text there are ng-minlength and ng-maxlength whereas for type="number" there are min and max properties.

<input ng-model="name2" name="name2" type="number" class="zoomIn" min="2" max="4" ng-pattern="/^\d+$/" placeholder="Your Annual Net Profit" required>
<div ng-messages="step5form.name2.$error">
<div ng-message="min">Please enter a value between 100000 and 20000000.</div>
<div ng-message="max">Please enter a value between 100000 and 20000000.</div>
<div ng-message="pattern">Annual net profit cannot be characters.</div>

Hope this will help you.

Updated : To remove input spinners add this css

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
input[type="number"] {
    -moz-appearance: textfield;
}
Sign up to request clarification or add additional context in comments.

9 Comments

but by putting type= number it shows up and down arrow in the input field.
To remove that there are ways. Just because there are spinners you cant do that. I have updated my answer please accept it if you found beneficial
i have put the css given by you but still arrows are not going
I have updated one more css try that and still you have any problem please make a plunker.
plnkr.co/edit/0Og86OO2Z26IRohVGmOF?p=preview here i have created the plunk. also on changing input type to number its not throwing the error message can not accept characters. is there any way to keep input type to text and still able to display the range error message
|
0

Use in Angular way:

<input type="number"
       ng-model="string"
       [name="string"]
       [min="string"]
       [max="string"]
       [required="string"]
       [ng-required="string"]
       [ng-minlength="number"]
       [ng-maxlength="number"]
       [pattern="string"]
       [ng-pattern="string"]
       [ng-change="string"]>

Angular Way - More detail

Or by Own Directory

http://jsfiddle.net/webvitaly/AG2wf/1/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.