locked
HOW TO Restrict user from entering special characters in textbox using javascript RRS feed

  • Question

  • User1865404792 posted
    I have this code, but it doesn't work
    <%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="services.aspx.cs" Inherits="services" %>
    
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta charset="utf-8" />   <!-- قبول الرموز في المتصفح -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />   <!-- توافق العمل مع اكسبلورر -->
        <meta name="viewport" content="width=device-width, initial-scale=1" />   <!-- التوافق مع الموبايل -->
        <title>Services</title>
    
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js"></script>
        <link rel="Stylesheet" type="text/css" href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css" />
    <script type="text/javascript"> $(function () { $("[id$=TextBox1]").autocomplete({ source: function (request, response) { $.ajax({ url: '<%=ResolveUrl("~/services.aspx/GetCompletionList") %>', data: "{ 'prefixText': '" + request.term + "'}", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", success: function (data) { response($.map(data.d, function (item) { return { label: item.split('-')[0], val: item.split('-')[1] } })) }, error: function (response) { alert(response.responseText); }, failure: function (response) { alert(response.responseText); } }); }, select: function (e, i) { $("[id$=hfdoc_no]").val(i.item.val); }, ///////////هذا القسم يقو باضهار رساله في حاله قام المستخدم بكتابة اسم من خارج القائمة change:function(e, ui){ if(!(ui.item)){ e.target.value=""; alert("إختيار الطبيب من القائمة فقط"); } }, /////////// minLength: 1 }); }); </script> <!-- هذا الوسم التالي يقوم بعمل سكرول بار للاوتوكمبليت--> <!-- ولكنه يعمل فقط على فاير فوكس وكروم ولكن في الكروم تضهر قائمتين قائمة الجافا مع السكرول بار--> <!-- والقائمة الرئيسية السابقه الطويله ولذلك سندخل لخصائل التكتس بوكس ومن خاصية الاوتوكمبليت في الخاصيه انبل نجعلها فولس--> <style type="text/css"> .ui-autocomplete { ; cursor:default; max-height:250px; overflow-y:scroll; overflow-x:hidden; -webkit-overflow-scrolling:touch; } </style> <style type="text/css"> .auto-style1 { text-align: center; } .auto-style3 { font-size: large; color: #990033; } .auto-style4 { font-size: large; text-align: center; background-color: #F0F0F0; } .auto-style5 { width: 83px; } .auto-style6 { text-align: center; font-size: large; } .auto-style7 { width: 83px; text-align: justify; } .auto-style8 { font-size: x-large; } .auto-style9 { width: 6px; } .auto-style10 { background-color: #F0F0F0; } .auto-style11 { text-align: right; } .auto-style12 { color: #CC0066; font-size: x-large; } .auto-style1 { font-size: large; font-weight: 700; text-align: center; } </style> <!--لاضافة فقط ارقام في حق الكمية والسعر--> <script type="text/javascript"> function CheckNumeric(e) { if (window.event) // IE { if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8) { event.returnValue = false; return false; } } else { // Fire Fox if ((e.which < 48 || e.which > 57) & e.which != 8) { e.preventDefault(); return false; } } } </script> <script type="text/javascript"> var specialKeys = new Array(); specialKeys.push(35); //# specialKeys.push(37); //% specialKeys.push(43); //+ specialKeys.push(45); //- specialKeys.push(61); //= specialKeys.push(64); //@ function IsAlphaNumeric(e) { var ret; var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode; ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode)); if (specialKeys.indexOf(keyCode) != -1) { ret = true; } document.getElementById("error").style.display = ret ? "none" : "inline"; return ret; } </script> </head> <body> <script type="text/javascript"> function mathprice() { $('#<%=txtprice.ClientID %>').keyup(function () { var a = $('#<%=txtprice.ClientID %>').val(); var b = $('#<%=txtqun.ClientID %>').val(); var r = (b * a); //var result = Math.round(r * 100) / 100; $('#<%=txttotal.ClientID %>').val(r); }); $('#<%=txtqun.ClientID %>').keyup(function () { var a = $('#<%=txtqun.ClientID %>').val(); var b = $('#<%=txtprice.ClientID %>').val(); var r = (b * a); //var result = Math.round(r * 100) / 100; $('#<%=txttotal.ClientID %>').val(r); }); }; </script> <form id="form1" runat="server"> <div > <table align="center" class="auto-style10"> <tr> <td class="auto-style1" colspan="5"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> </td> </tr> <tr> <td class="auto-style1" colspan="5"> <asp:Image ID="Image1" runat="server" Height="88px" ImageUrl="~/img/serv.png" Width="353px" /> </td> </tr> <tr> <td>&nbsp;</td> <td class="auto-style11" colspan="3"> <asp:Label ID="Label11" runat="server" Text="Label" Width="270px"></asp:Label> <asp:Label ID="Label10" runat="server" Text=":المستخدم"></asp:Label> </td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td class="auto-style1"> <asp:Button ID="btnback" runat="server" CssClass="auto-style3" Height="35px" Text="رجوع للرئيسية" Width="140px" OnClick="Button2_Click" CausesValidation="False" /> </td> <td class="auto-style1" colspan="2"> <asp:Button ID="Button1" runat="server" CssClass="auto-style3" Height="35px" Text="تسجيل خدمة جديده" Width="150px" OnClick="Button1_Click" CausesValidation="False" /> </td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td colspan="2"> <asp:HiddenField ID="hfdoc_no" runat="server" /> </td> <td> </td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td colspan="2"> <asp:TextBox ID="txtdate" runat="server" Height="30px" Width="230px" Enabled="False" CssClass="auto-style4" BorderColor="#F0F0F0" BorderStyle="None"></asp:TextBox> </td> <td class="auto-style1">:التاريخ</td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td colspan="2"> <asp:DropDownList ID="DropDownList1" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="35px" Width="240px" BackColor="White" Enabled="False"> </asp:DropDownList> </td> <td class="auto-style6"><strong>:المدينة</strong></td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td colspan="2"> <asp:DropDownList ID="DropDownList2" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="35px" Width="240px" BackColor="White" Enabled="False"> </asp:DropDownList> </td> <td class="auto-style1"><strong> <asp:Label ID="Label3" runat="server" CssClass="auto-style4" Text=":الشركة"></asp:Label> </strong></td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td colspan="2"> <asp:TextBox ID="TextBox1" runat="server" onpaste="return false" oncopy="return false" oncut="return false" Height="30px" style="font-size: large; font-weight: 700" Width="230px" Enabled="False"></asp:TextBox> <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" Enabled="False" CompletionInterval="500"> </cc1:AutoCompleteExtender> </td> <td class="auto-style1"><strong> <asp:Label ID="Label4" runat="server" CssClass="auto-style4" Text=":الطبيب"></asp:Label> </strong></td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtser" CssClass="auto-style12" ErrorMessage="ادخل بيان الخدمة">*</asp:RequiredFieldValidator> </td> <td colspan="2"> <asp:TextBox onkeypress="return IsAlphaNumeric(event);" ID="txtser" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="80px" TextMode="MultiLine" Width="238px" BackColor="White" Enabled="False" autocomplete="off"></asp:TextBox> </td> <td class="auto-style1"><strong> <asp:Label ID="Label5" runat="server" CssClass="auto-style4" Text=":الخدمة"></asp:Label> </strong></td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtqun" CssClass="auto-style12" ErrorMessage="ادخل الكمية">*</asp:RequiredFieldValidator> </td> <td class="auto-style7"><strong> <asp:TextBox ID="txtqun" onkeypress = "CheckNumeric(event);" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox> </strong></td> <td class="auto-style1"><strong> <asp:Label ID="Label6" runat="server" CssClass="auto-style4" Text=":الكمية"></asp:Label> </strong></td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtprice" CssClass="auto-style12" ErrorMessage="ادخل السعر">*</asp:RequiredFieldValidator> </td> <td class="auto-style5"><strong> <asp:TextBox ID="txtprice" onkeypress = "CheckNumeric(event);" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox> </strong></td> <td class="auto-style1"><strong> <asp:Label ID="Label7" runat="server" CssClass="auto-style4" Text=":السعر"></asp:Label> </strong></td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td class="auto-style5"><strong> <asp:TextBox ID="txttotal" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox> </strong></td> <td class="auto-style1"><strong> <asp:Label ID="Label8" runat="server" CssClass="auto-style4" Text=":الاجمالي"></asp:Label> </strong></td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td class="auto-style5">&nbsp;</td> <td>&nbsp;</td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td><strong> <asp:Button ID="btnsave" runat="server" CssClass="auto-style4" OnClick="btnsave_Click" Text="حفظ" Width="88px" Enabled="False" /> </strong></td> <td class="auto-style5">&nbsp;</td> <td>&nbsp;</td> <td class="auto-style9">&nbsp;</td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td class="auto-style5">&nbsp;</td> <td> <asp:Label ID="lblman_no" runat="server"></asp:Label> </td> <td class="auto-style9">&nbsp;</td> </tr> </table> </div> </form> </body> </html>

    Thursday, September 3, 2020 9:00 AM

Answers

  • User1535942433 posted

    Hi alhakimy,

    Accroding to your requirment that the textbox accept Arabic letters and the space,the space's keycode is 32 and you could use regex to accept Arabic letters.

    You could refer to below codes:

     <script type="text/javascript">
            var specialKeys = new Array();
            specialKeys.push(35); //#
            specialKeys.push(37); //%
            specialKeys.push(43); //+
            specialKeys.push(45); //-
            specialKeys.push(61); //=
            specialKeys.push(64); //@
    
            function IsAlphaNumeric(e) {
                var arabicCharUnicodeRange = /[\u0600-\u06FF]/;
                var ret;
                var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
                var str = String.fromCharCode(keyCode);
                ret = ((keyCode == 32) || (keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode)||(arabicCharUnicodeRange.test(str)));
                if (ret == false) { return false; }
                else { return true;}     
            }
    
        </script>

    Result:

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 8, 2020 5:57 AM

All replies

  • User1535942433 posted

    Hi alhakimy,

    Accroding to your description and codes,could you tell us where the control id is error?I find your problem is miss the control to show the error.

    More details,you could refer to below codes:

     <script type="text/javascript">
            var specialKeys = new Array();
            specialKeys.push(35); //#
            specialKeys.push(37); //%
            specialKeys.push(43); //+
            specialKeys.push(45); //-
            specialKeys.push(61); //=
            specialKeys.push(64); //@
    
            function IsAlphaNumeric(e) {
                var ret;
                var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
                ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
                if (specialKeys.indexOf(keyCode) != -1) {
                    ret = true;
                }
                document.getElementById("error").style.display = ret ? "none" : "inline";
                  return ret;
            
            }
        </script>  
    
    
     <table align="center" class="auto-style10">
                    <tr>
                        <td class="auto-style1" colspan="5">
                            <asp:ScriptManager ID="ScriptManager1" runat="server">
                            </asp:ScriptManager>
                        </td>
                    </tr>
                    <tr>
                        <td class="auto-style1" colspan="5">
    <%--                        <asp:Image ID="Image1" runat="server" Height="88px" ImageUrl="~/img/serv.png" Width="353px" />--%>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="auto-style11" colspan="3">
                            <asp:Label ID="Label11" runat="server" Text="Label" Width="270px"></asp:Label>
                            <asp:Label ID="Label10" runat="server" Text=":المستخدم"></asp:Label>
                        </td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="auto-style1">
                            <asp:Button ID="btnback" runat="server" CssClass="auto-style3" Height="35px" Text="رجوع للرئيسية" Width="140px" OnClick="btnback_Click" CausesValidation="False" />
                        </td>
                        <td class="auto-style1" colspan="2">
                            <asp:Button ID="Button1" runat="server" CssClass="auto-style3" Height="35px" Text="تسجيل خدمة جديده" Width="150px" OnClick="Button1_Click" CausesValidation="False" />
                        </td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:HiddenField ID="hfdoc_no" runat="server" />
                        </td>
                        <td></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:TextBox ID="txtdate" runat="server" Height="30px" Width="230px" Enabled="False" CssClass="auto-style4" BorderColor="#F0F0F0" BorderStyle="None"></asp:TextBox>
                        </td>
                        <td class="auto-style1">:التاريخ</td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:DropDownList ID="DropDownList1" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="35px" Width="240px" BackColor="White" Enabled="False">
                            </asp:DropDownList>
                        </td>
                        <td class="auto-style6"><strong>:المدينة</strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:DropDownList ID="DropDownList2" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="35px" Width="240px" BackColor="White" Enabled="False">
                            </asp:DropDownList>
                        </td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label3" runat="server" CssClass="auto-style4" Text=":الشركة"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:TextBox ID="TextBox1" runat="server" onpaste="return false" oncopy="return false" oncut="return false" Height="30px" Style="font-size: large; font-weight: 700" Width="230px" Enabled="False"></asp:TextBox>
                            <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" Enabled="False" CompletionInterval="500"></cc1:AutoCompleteExtender>
                        </td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label4" runat="server" CssClass="auto-style4" Text=":الطبيب"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtser" CssClass="auto-style12" ErrorMessage="ادخل بيان الخدمة">*</asp:RequiredFieldValidator>
                        </td>
                        <td colspan="2">
                            <asp:TextBox onkeypress="return IsAlphaNumeric(event);" ID="txtser" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="80px" TextMode="MultiLine" Width="238px" BackColor="White" autocomplete="off"></asp:TextBox>
                        </td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label5" runat="server" CssClass="auto-style4" Text=":الخدمة"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td> <asp:Label ID="error" runat="server" CssClass="labeldisplay" Text="Special characters" ForeColor="Red"></asp:Label></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtqun" CssClass="auto-style12" ErrorMessage="ادخل الكمية">*</asp:RequiredFieldValidator>
                        </td>
                        <td class="auto-style7"><strong>
                            <asp:TextBox ID="txtqun" onkeypress="CheckNumeric(event);" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox>
                        </strong></td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label6" runat="server" CssClass="auto-style4" Text=":الكمية"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtprice" CssClass="auto-style12" ErrorMessage="ادخل السعر">*</asp:RequiredFieldValidator>
                        </td>
                        <td class="auto-style5"><strong>
                            <asp:TextBox ID="txtprice" onkeypress="CheckNumeric(event);" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox>
                        </strong></td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label7" runat="server" CssClass="auto-style4" Text=":السعر"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style5"><strong>
                            <asp:TextBox ID="txttotal" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox>
                        </strong></td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label8" runat="server" CssClass="auto-style4" Text=":الاجمالي"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style5">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><strong>
                            <asp:Button ID="btnsave" runat="server" CssClass="auto-style4" OnClick="btnsave_Click" Text="حفظ" Width="88px" Enabled="False" />
                        </strong></td>
                        <td class="auto-style5">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style5">&nbsp;</td>
                        <td>
                            <asp:Label ID="lblman_no" runat="server"></asp:Label>
                        </td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                </table>

    Result:

    Best regards,

    Yijing Sun

    Friday, September 4, 2020 6:12 AM
  • User1865404792 posted

    thank you yij sun

    Thank you for the clarification
    I did not know that the message will be shown by Label

    But I do not want this label
    I want the symbol not to be written when clicking on it

    Saturday, September 5, 2020 6:04 AM
  • User1535942433 posted

    Hi alhakimy,

    Accroding to your description, I don't understand your requirment clearly.I‘m guessing that you need to prevent user entering special characters and don't show the error message.Do you need that when user enters the special characters,the characters cann't be displayed? 

    If you need the requirment,as far as I think,the method may cause user don't know the special characters cann't be entered.I suggest you could give users messages that the special characters cann't be entered.

    Below codes works that it will prevent users to enter the special characters and the special characters cann't be entered.

    <script type="text/javascript">
            var specialKeys = new Array();
            specialKeys.push(35); //#
            specialKeys.push(37); //%
            specialKeys.push(43); //+
            specialKeys.push(45); //-
            specialKeys.push(61); //=
            specialKeys.push(64); //@
    
            function IsAlphaNumeric(e) {
                var ret;
                var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
                ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
                if (ret == false) { return false; }
                else { return true;}     
            }
        </script>  
    
    
    <div>
                <table align="center" class="auto-style10">
                    <tr>
                        <td class="auto-style1" colspan="5">
                            <asp:ScriptManager ID="ScriptManager1" runat="server">
                            </asp:ScriptManager>
                        </td>
                    </tr>
                    <tr>
                        <td class="auto-style1" colspan="5">
    <%--                        <asp:Image ID="Image1" runat="server" Height="88px" ImageUrl="~/img/serv.png" Width="353px" />--%>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="auto-style11" colspan="3">
                            <asp:Label ID="Label11" runat="server" Text="Label" Width="270px"></asp:Label>
                            <asp:Label ID="Label10" runat="server" Text=":المستخدم"></asp:Label>
                        </td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="auto-style1">
                            <asp:Button ID="btnback" runat="server" CssClass="auto-style3" Height="35px" Text="رجوع للرئيسية" Width="140px" OnClick="btnback_Click" CausesValidation="False" />
                        </td>
                        <td class="auto-style1" colspan="2">
                            <asp:Button ID="Button1" runat="server" CssClass="auto-style3" Height="35px" Text="تسجيل خدمة جديده" Width="150px" OnClick="Button1_Click" CausesValidation="False" />
                        </td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:HiddenField ID="hfdoc_no" runat="server" />
                        </td>
                        <td></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:TextBox ID="txtdate" runat="server" Height="30px" Width="230px" Enabled="False" CssClass="auto-style4" BorderColor="#F0F0F0" BorderStyle="None"></asp:TextBox>
                        </td>
                        <td class="auto-style1">:التاريخ</td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:DropDownList ID="DropDownList1" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="35px" Width="240px" BackColor="White" Enabled="False">
                            </asp:DropDownList>
                        </td>
                        <td class="auto-style6"><strong>:المدينة</strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:DropDownList ID="DropDownList2" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="35px" Width="240px" BackColor="White" Enabled="False">
                            </asp:DropDownList>
                        </td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label3" runat="server" CssClass="auto-style4" Text=":الشركة"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <asp:TextBox ID="TextBox1" runat="server" onpaste="return false" oncopy="return false" oncut="return false" Height="30px" Style="font-size: large; font-weight: 700" Width="230px" Enabled="False"></asp:TextBox>
                            <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" Enabled="False" CompletionInterval="500"></cc1:AutoCompleteExtender>
                        </td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label4" runat="server" CssClass="auto-style4" Text=":الطبيب"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtser" CssClass="auto-style12" ErrorMessage="ادخل بيان الخدمة">*</asp:RequiredFieldValidator>
                        </td>
                        <td colspan="2">
                            <asp:TextBox onkeypress="return IsAlphaNumeric(event);" ID="txtser" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style4" Height="80px" TextMode="MultiLine" Width="238px" BackColor="White" autocomplete="off"></asp:TextBox>
                        </td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label5" runat="server" CssClass="auto-style4" Text=":الخدمة"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td> <asp:Label ID="error" runat="server" CssClass="labeldisplay" Text="Special characters" ForeColor="Red"></asp:Label></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtqun" CssClass="auto-style12" ErrorMessage="ادخل الكمية">*</asp:RequiredFieldValidator>
                        </td>
                        <td class="auto-style7"><strong>
                            <asp:TextBox ID="txtqun" onkeypress="CheckNumeric(event);" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox>
                        </strong></td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label6" runat="server" CssClass="auto-style4" Text=":الكمية"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtprice" CssClass="auto-style12" ErrorMessage="ادخل السعر">*</asp:RequiredFieldValidator>
                        </td>
                        <td class="auto-style5"><strong>
                            <asp:TextBox ID="txtprice" onkeypress="CheckNumeric(event);" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox>
                        </strong></td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label7" runat="server" CssClass="auto-style4" Text=":السعر"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style5"><strong>
                            <asp:TextBox ID="txttotal" runat="server" onpaste="return false" oncopy="return false" oncut="return false" CssClass="auto-style8" Width="79px" Enabled="False" autocomplete="off"></asp:TextBox>
                        </strong></td>
                        <td class="auto-style1"><strong>
                            <asp:Label ID="Label8" runat="server" CssClass="auto-style4" Text=":الاجمالي"></asp:Label>
                        </strong></td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style5">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><strong>
                            <asp:Button ID="btnsave" runat="server" CssClass="auto-style4" OnClick="btnsave_Click" Text="حفظ" Width="88px" Enabled="False" />
                        </strong></td>
                        <td class="auto-style5">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="auto-style5">&nbsp;</td>
                        <td>
                            <asp:Label ID="lblman_no" runat="server"></asp:Label>
                        </td>
                        <td class="auto-style9">&nbsp;</td>
                    </tr>
                </table>
    
            </div>

    Best regards,

    Yijing Sun

    Monday, September 7, 2020 6:30 AM
  • User1865404792 posted
    It does not accept Arabic letters as well as the space 
    Monday, September 7, 2020 8:56 AM
  • User1535942433 posted

    Hi alhakimy,

    Accroding to your requirment that the textbox accept Arabic letters and the space,the space's keycode is 32 and you could use regex to accept Arabic letters.

    You could refer to below codes:

     <script type="text/javascript">
            var specialKeys = new Array();
            specialKeys.push(35); //#
            specialKeys.push(37); //%
            specialKeys.push(43); //+
            specialKeys.push(45); //-
            specialKeys.push(61); //=
            specialKeys.push(64); //@
    
            function IsAlphaNumeric(e) {
                var arabicCharUnicodeRange = /[\u0600-\u06FF]/;
                var ret;
                var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
                var str = String.fromCharCode(keyCode);
                ret = ((keyCode == 32) || (keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode)||(arabicCharUnicodeRange.test(str)));
                if (ret == false) { return false; }
                else { return true;}     
            }
    
        </script>

    Result:

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 8, 2020 5:57 AM
  • User1865404792 posted
    Thank you so much
    more than great
    Tuesday, September 8, 2020 1:49 PM