Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how we allow only alphabet and numeric values in textbox in asp.net(others are not valid like special chaacters)
Posted

1 solution

XML
hi,

Try this javascript
<pre lang="xml">&lt;script type=&quot;text/javascript&quot;&gt;

       function onlyAlphaNumeric(evt) {
           if (!(evt.keyCode &gt;= 48 &amp;&amp; evt.keyCode &lt;= 57)) {
               if (!(evt.keyCode &gt;= 65 &amp;&amp; evt.keyCode &lt;= 90)) {
                   if (!(evt.keyCode &gt;= 97 &amp;&amp; evt.keyCode &lt;= 122))
                       return false;
               }
           }
       }
   &lt;/script&gt;</pre>

calling of javascript function


on page load event

C#
protected void Page_Load(object sender, EventArgs e)
   {
      txtBox1.Attributes["onkeypress"] = "return onlyAlphaNumeric(event);";
   }


hope this help u

Best Luck happy coding
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900