how to allow only character (a-z) and number(0-9) only in the textbox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hidayu1986
    New Member
    • Mar 2010
    • 7

    how to allow only character (a-z) and number(0-9) only in the textbox?

    currently i try this code but:
    Code:
    -->for alphanumeric(allow alphanumeric : a-z,0-9,(symbol))
    <asp:textbox onkeypress="if(((event.keyCode>=39)&amp;&amp;(even t.keyCode<=39))){event.returnValue=false;}"
    id="txtStfNo" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="440px" Height="60px"></asp:textbox>
    
    
    
    <asp:textbox onkeypress="if(((event.keyCode>=39)&amp;&amp;(even t.keyCode<=39))){event.returnValue=false;}"
    id="txtccno" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="440px" Height="60px"></asp:textbox>
    
    
    --->allow numeric only
    <asp:textbox onkeypress="if(((event.keyCode>=32)&amp;&amp;(even t.keyCode<=47))||((event.keyCode>=58)&amp;&amp;(ev ent.keyCode<=254))){event.returnValue=false;}"
    id="Textbox1" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="152px"></asp:textbox>
    
    ---allow symbol only
    <asp:textbox onkeypress="if(((event.keyCode>=48)&amp;&amp;(even t.keyCode<=57))||((event.keyCode>=65)&amp;&amp;(ev ent.keyCode<=90))||((event.keyCode>=97)&amp;&amp;( event.keyCode<=122)) ){event.returnValue=false;}"
    id="Textbox1" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="152px"></asp:textbox>
    but i want to allow only a-z character and 0-9 number into the textbox. not allow any symbol
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    event.returnVal ue=false;
    I thought you were supposed to return true, but I could be mistaken.

    I suggest writing external functions to make the code cleaner. Then you could have those functions call other functions, like IsDigit(), IsLetter(), IsSymbol(), etc.

    Also, you've posted in the wrong forum.

    Comment

    Working...