I have an html <input type="number"> box that has some custom validation logic. A valid value is any integer x where x < -100 OR x >= 100.
My goal is to implement this behavior:
- when the user clicks on the native down arrow or presses the down arrow key and the current value is
100, the value changes to-101. - similarly when the user clicks on the native up arrow or presses the up arrow key and the current value is
-101, the value changes to100.
A few caveats:
- Users must still be able to type numbers that fall within the invalid range since they may need to type
10in order to type109. And validation logic already occurs for this. - I am using angularjs, but I suspect that the solution is not going to be angular specific.
- This is an internal application, meant for Chrome only, so browser specific answers are fine.
I think I have what you need, or at least I'm getting close:
codepen: http://codepen.io/anon/pen/Ndqbog
-100 -> 100,99 -> -101).-100 -> -101,99 -> 100).-100 -> -101).But if you need thresholds with different lengths, you can always change the
String(Math.abs(x)).length>2to an extra if-clause and first check whether the value is positive or negative, and then check for separate lengths.