I have a text box. I want to restrict user to only copy paste numeric.I dont want copy paste of alphabets and special characters. I have tried below code with out success.
<!DOCTYPE html>
<html ng-app="plnk">
<head>
<script data-require="angular.js@*" data-semver="2.0.0" src="https://ajax.googleapis`enter code here`.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
<script src="app.js"></script>
</head>
<body>
<h1>Disable copy paste</h1>
for testing if angular is working {{1+1}}
<br/>
<input stopcopypaste ng-model="val" />
</body>
</html>
javascript :
var app = angular.module('plnk', []);
app.controller('MainCtrl', function($scope, $timeout) {
$scope.val = '1';
});
app.directive('stopcopypaste', function(){
return {
scope: {},
link:function(scope,element){
element.on('cut copy paste', function (event) {
key = event.keyCode || event.which;
if ((47 < key) && (key < 58) || key == 8 || key == 189 || key == 109) {
return true;
} else {
event.preventDefault();
return false;
}
})
})
}
};
});
I cannot restrict the alphabets and special characters with this code.