简体   繁体   English

用户复制和粘贴内容时,如何根据禁止的输入检查复制的数据?

[英]How do i check the copied data against banned inputs when user copy & paste content?

I am developing one application that has form builder inside it to build the form. 我正在开发一个内部有表单生成器的应用程序来构建表单。 In that, i have considered special character '#' & '[]' for backend data processing against form & so i have banned user from typing the key buttons on keyboard for the respective characters too. 在这种情况下,我考虑了特殊字符“#”和“ []”用于针对表单&进行后端数据处理,因此我也禁止用户为相应字符键入键盘上的按键。 Thing is i am done with banning user from typing so but if user copies the content from somewhere & paste into the place which supposed to contain above characters the i want to check before user pastes, the data against banned inputs. 我已经完成了禁止用户输入的操作,但是如果用户从某处复制内容并将其粘贴到应该包含上述字符的位置,则我想在用户粘贴之前检查该数据,以禁止输入。 My concern is this but dont know how to do it or is it possible to do so or any other way to resolve this issue??? 我的担心是这样,但不知道该怎么办,或者有可能这样做或以其他任何方式解决此问题?

Thanks in advance for inputs... 预先感谢您的投入...

Preventing the user from pressing unwanted keyes is not the best way to solve this problem. 防止用户按下不需要的键不是解决此问题的最佳方法。 In principle you have two problem domains: 原则上,您有两个问题域:

1) Preventing malicious inputs from your form to go over the wire. 1)防止表单中的恶意输入通过网络传播。 The best way to do that would be to use jQuery submit() and write a validation function which a) cleans input and sends it over the wire or b) prevents submitting and shows the user an error message, not to enter malicious input. 最好的方法是使用jQuery Submit()并编写一个验证函数,其中a)清理输入并通过网络发送它,或者b)阻止提交并向用户显示错误消息,而不是输入恶意输入。

2) You have to be concerned, that the user could bypass your form implementation and uses curl or other tools to circumvent validation on site. 2)您必须担心,用户可能会绕过您的表单实现并使用curl或其他工具来绕过现场验证。 So, you have to take care in the backend, that the input is sanitized, before processed further. 因此,在进一步处理之前,您必须在后端注意对输入进行清理。

 $("textarea").bind('paste', function(e) {
      var self = this;
      setTimeout(function(e) {
           var textval=$(self.val());
           //Replace the banned keys with your custom
           $("textarea").val(textval);
      }, 0);
 });

Try something like this: 尝试这样的事情:

 $('#yourTextAreaId').on('paste', function (e) { 
        pasteContent = e.target.value;

        //implement containsSpecialChars function
        if(containsSpecialChars(pasteContent)){ 
           e.preventDefault()
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM