Reputation: 845
I'm trying to create an input mask.
I want delete and arrow key functionality plus all the other keys except 1 2 3 4 5 6. I'm using 1, 2, 3, 4, 5, 6 as hotkeys for a scheduling app. Is it possible in angular to create a mask that just disables the numbers one through six?
<input pattern="regex"> <!-- not working because it only fires after submit -->
Upvotes: 0
Views: 1298
Reputation: 2658
You can use angular ng-pattern
to achieve this:
<input type="text" ng-model="check" name="check" ng-pattern="/^[^1-6.]*$/">
<small class="error" ng-show="exampleForm.check.$error.pattern">Invalid pattern.</small>
Dynamically checks for invalid key enter not on submit.
Upvotes: 0
Reputation: 8484
<input type="text" ng-keypress="keyPressed($event)">
In controller
function MyCtrl($scope){
$scope.keyPressed = function(e) {
if (e.keyCode >= 49 && e.keyCode <= 54) {
event.preventDefault();
} else {
// do your logic
}
}
}
You can do with ng-pattern
attribute but it allows the character and do the validation but your requirement is to disable characters.
Upvotes: 3