I am using Angular and I want to easely validate a number input. I want that when the user type a value out of range in an input( below 1 and greater than 99) the Input doesn't change. I don't want to use forms.
I have designed a component that displays dynamic data in several parts, I achieved it without using the form facilities of Angular. The only issue left is that the user cannot enter values below 1 and greater than 99 on a number input. The type of input is number. I don't know how can I prevent the user from entering letters and values out of range(less than 1 and greater than 99) without using Angular's forms. The inputs are generated dynamically using ngFor. The input behavior(allowing the user to type anything, even though we use number type), the HTML5 validation features that are so bad, and Angular lack of flexibility to handle small problems are cornering me.
My last attempt:
template:
<input (change)="alterQuantity(index, $event)" >
component:
alterQuantity(index: number, event: any)
{
var re = new RegExp("[1-99]");
if (!re.test(event.target.value)) {
event.stopPropagation();
event.preventDefault();
return;
}
}