allow only Arabic Letters in textbox using JavaScr

2020-07-24 06:10发布

I have aspx page that have TextBox control for " User Arabic Name" I want to Allow user to type only arabic letters in textbox using JavaScript

2条回答
Explosion°爆炸
2楼-- · 2020-07-24 06:37

"ذض ص ث ق ف غ ع ه خ ح ج دش س ي ب ل ا ت ن م ك ط ئءؤرلاى ةوزظ .acbdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

This string combined with above solution will allow users to type any english or arabic character with additional allow of a dot (.)

查看更多
3楼-- · 2020-07-24 07:02

First you make text box like below :

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

then add javascript method :

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

Now you have to enter all arabic characters in strCheck like above example

查看更多
登录 后发表回答