0
votes

I have a number text box with min and max values.I given min="0" and max="9".But user can able to enter more than 9 like 10,100 etc..

<input style='width:125px;' ng-model='decimalvalues' min='0' max='9'
       ng-init='decimalvalues=4'
       data-ng-change=" + Decimalplaces + " 
       type='number'
       id='decimalvalues'/>"
1
What you have described should work. Are you able to create a minimal reproducible example - either in a snippet or jsfiddle - where the community can see the problem and understand how it might be resolved? - Alexander Nied
normally on key up and key down it is showing between 0 and 9,but on key press user can enter more than 9 - Akhil

1 Answers

1
votes

What you describe is the default behavior of min/max. These attributes are used for validation, they can't prevent user from entering invalid values. If user enters a value bigger than max, form control becomes $invalid and $error object is filled with: {"max":true}. You can use that values to show an error message to user. (If you want to prevent user from entering a wrong value, then a custom directive is needed)

Read more here to understand how validation works:

Check a working example with error messages: DEMO

Also, you ng-change expression is invalid, you should remove or replace it.