簡體   English   中英

限制特殊字符並允許使用字母

[英]To restrict Special Characters and allow alphabets

在下面的代碼中,我想允許字母集並限制特殊字符,但是它允許特殊字符.pls幫助我解決了這個問題。

JS:

function AcceptAlphabetsOnly(e, t) {
    try {
        if (window.event) {
            var charCode = window.event.keyCode;
        }
        else if (e) {
            var charCode = e.which;
        }
        else { return true; }
        if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
            return true;
        else
            return false;
    }
    catch (err) {
        alert(err.Description);
    }
};

Asp.net

<input name="data[Customer][name]" type="text" 
                             id="txtVendor" runat="server" onkeypress="return AcceptAlphabetsOnly(event,this);" />

試試下面的功能

function checkSpcialChar(event){
    if (!((event.keyCode >= 65) && (event.keyCode <= 90) || (event.keyCode >= 97) && (event.keyCode <= 122) || (event.keyCode >= 48) && (event.keyCode <= 57))) {
        event.returnValue = false;
        return;
    }
    event.returnValue = true;
}

暫無
暫無

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

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