簡體   English   中英

Asp.net文本框復制和粘貼

[英]Asp.net Text box Copy & Paste

我使用了Asp.net文本框,並使用Javascript驗證(鍵盤ASCII代碼)進行了一些很好的按鍵限制,我需要的是從其他地方復制時將其粘貼到此處,我需要限制某些按鍵。 例如-我要在粘貼時限制或禁用“”。

function AlphaNumeric(evt)
{
    var AsciiCode = (evt.which) ? evt.which : event.keyCode
    if (AsciiCode > 64 && AsciiCode < 91 || AsciiCode > 96 && AsciiCode < 123 || AsciiCode > 47 && AsciiCode < 58 || AsciiCode == 127 || AsciiCode == 8 || AsciiCode == 32 || AsciiCode == 45 || AsciiCode == 95)
    {
        return true;
    }
    else
    {
        return false;
    }           
}

您可以使用regx表達式並將其綁定到DOM准備就緒的Paste事件上

這是代碼段演示

HTML

<input id="textInput" name="textInput">

jQuery的

$("#textInput").bind('paste', function() {
  setTimeout(function() {
    //get the value of the input text
    var data = $('#textInput').val();
    //replace the special characters to '' 
    var dataFull = data.replace(/\(|\)/g, '');
    //set the new value of the input text without special characters
    $('#textInput').val(dataFull);
  });

});

嘗試這個,

if(ASCII==22 && ASCII==41)
  return false;

最后我用這個...

$(function(){

    $('#txt_box').keyup(function()
    {
        var yourInput = $(this).val();
        re = /[`~!@#$%^&*()|+\=?;:'",.<>\{\}\[\]\\\/]/gi;
        var isSplChar = re.test(yourInput);
        if(isSplChar)
        {
            var no_spl_char = yourInput.replace(/[`~!@#$%^&*()|+\=?;:'",.<>\{\}\[\]\\\/]/gi, '');
            $(this).val(no_spl_char);
        }
    });

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM