Asp.net文本框Copy&糊

时间:2017-04-28 06:41:48

标签: javascript asp.net

我使用了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;
    }           
}

3 个答案:

答案 0 :(得分:0)

您可以使用regx表达式并将其绑定到Paste就绪的DOM事件

这是代码段Demo

<强> 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);
  });

});

答案 1 :(得分:0)

试试这个,

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

答案 2 :(得分:0)

最后我用了这个......

$(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);
        }
    });

});