只允许使用JavaScript在文本框中显示阿拉伯字母

allow only Arabic Letters in textbox using JavaScript

本文关键字:显示 阿拉伯 文本 许使用 JavaScript      更新时间:2023-10-28

我有一个aspx页面,该页面具有"用户阿拉伯名称"的TextBox控件我想允许用户使用JavaScript 在文本框中只键入阿拉伯字母

首先,您制作如下文本框:

<asp:textbox id="txtbxr" runat="server"  onselectstart="return false" ondragstart="return false" onkeypress="return(KeyPressOrder(this,event))" onkeydown="(KeyPressOrder(this,event))" ></asp:textbox>

然后添加javascript方法:

function KeyPressOrder(fld, e) {
    var strCheck = '0123456789acbdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var whichCode = e.which ? e.which : e.keyCode;
        if (whichCode == 13 || whichCode == 8 || whichCode == 9) return true;
        key = String.fromCharCode(whichCode);
        if (strCheck.indexOf(key) == -1)
            return false;
    return true;
}

现在,您必须在strCheck中输入所有阿拉伯字符,如上面的示例

此字符串与上述解决方案相结合,将允许用户键入任何英文或阿拉伯字符,并允许使用点(.)