app.directive('allowPattern', [allowPatternDirective]);
function allowPatternDirective() {
return {
restrict: "A",
compile: function (tElement, tAttrs) {
return function (scope, element, attrs) {
element.bind("keypress", function (event) {
var keyCode = event.which || event.keyCode;
if ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122)) {
event.preventDefault();
return false;
}
});
};
}
};
}
<input type="text" allow-pattern="[0-9]" autofocus />
如何防止在粘貼文本時粘貼的內容不適用於這一領域? (應粘貼適用conten)
應用背景:C#,AngularJS
我在我的應用程序,它應該只接受數字文本框。目前我正在使用Keypress的指令來防止輸入非數字值。但是,當我複製粘貼非數字值與數值(例如:NUMBER123)時,它正在粘貼。但要求是它不應該粘貼。我如何通過適當的角度js指令/ jquery來實現這一點。
郵政代碼在這裏 – Sajeetharan
請仔細閱讀http://stackoverflow.com/help/how-to-ask和改造你的問題。提供更多詳細信息,包括您當前的代碼和您已經完成的工作將會使幫助變得更加容易 –