VOOZH about

URL: https://www.geeksforgeeks.org/angular-js/how-to-reset-an-input-value-when-limit-exceeds-using-angularjs/

⇱ How to Reset an Input Value when Limit Exceeds using AngularJS ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Reset an Input Value when Limit Exceeds using AngularJS ?

Last Updated : 12 Jul, 2025

The task is to handle an input field if the number entered by the user in the input exceeds some limit using angularJS. We define a limitTo directive and use it on an HTML input element. This directive is used for all the handling of overflowing limits. The directive calls a function on the keypress event where we can check for the limits. 

 

Example 1: This example sets the value of user input to 0 if its limit exceeds 100. 

Output: As soon as the user exceeds 100, the value is set back to 0. 

👁 Image
 

Example 2: In this example, we change the text based on the input limit. If the value of the input is less than 0 then it goes to 0. If its value is greater than 100 then it goes to 100 otherwise it stays as it is. 

Output:

👁 Image
 
Comment

Explore