So I have a custom textbox directive (it contains an input box inside).
所以我有一个自定义文本框指令(它包含一个输入框)。
<custom-textbox ng-paste=pasteFn($event)></custom-textbox>
When the user hits paste, I want to sanitize what was pasted (removes special characters + reduces the string length).
当用户点击粘贴时,我想清理粘贴的内容(删除特殊字符+减少字符串长度)。
I tried looking into the event object and it looks fairly large, so I'm not sure of the best way to modify this string.
我尝试查看事件对象,它看起来相当大,所以我不确定修改此字符串的最佳方法。
1 个解决方案
#1
1
Get the clipboard data and send it to your paste function like this:
获取剪贴板数据并将其发送到您的粘贴功能,如下所示:
<input ng-paste="clean($event.clipboardData.getData('text/plain'))" placeholder='paste here' ng-model="paste">
pasted: {{paste}}<br>
new string: {{myString}}
Then in your controller:
然后在你的控制器中:
$scope.clean = function(e){
var str = e;
$scope.myString = str.replace(/[^a-zA-Z ]/g, "");
}
Here's a Plunker
这是一个Plunker
#1
1
Get the clipboard data and send it to your paste function like this:
获取剪贴板数据并将其发送到您的粘贴功能,如下所示:
<input ng-paste="clean($event.clipboardData.getData('text/plain'))" placeholder='paste here' ng-model="paste">
pasted: {{paste}}<br>
new string: {{myString}}
Then in your controller:
然后在你的控制器中:
$scope.clean = function(e){
var str = e;
$scope.myString = str.replace(/[^a-zA-Z ]/g, "");
}
Here's a Plunker
这是一个Plunker