Please see this jsFiddle (Disclaimer - the ng-keydown function isn't calling but that is not the main issue in the fiddle)
I am trying to add validation for an input box so numbers (0-100) are allowed and nothing else through a regex I made. However it is not working as expected as when using this function:
$scope.validatebox = function (e) {
var element = e.target;
var element_val = $(element).val();
element_val = parseInt(element_val);
var reg = /^[1-9][0-9]?$|^100$/;
if (reg.test(element_val) === false) //validate
{
e.preventDefault();
return;
}
};
The e.preventDefault() acts funny and doesn't permit the user to enter any number if there is nothing in the input box.
How can I ammend my code to force proper validation on the user so he can only enter numbers 0-100.