Pages

Men

rh

4/11/2014

Code for Textbox should accept only Strings in Java Script


            function onlyAlphabets(evt) {

                var charCode;
                if (window.event)
                    charCode = window.event.keyCode;  //for IE
                else
                    charCode = evt.which;  //for firefox
                if (charCode == 32) //for <space> symbol
                    return false;
                if (charCode > 31 && charCode < 65) 
                    return false;
                if (charCode > 90 && charCode < 97)
                    return false;
                if (charCode > 122) 

                    return false;
                return true;
                }



In Asp.net
<asp:TextBox ID="txtFName" runat="server" CssClass="TextBox" TabIndex="2"
                                      Width="150px" AutoCompleteType="Disabled" onkeypress="return onlyAlphabets(event);"></asp:TextBox>

No comments :

Post a Comment