?
Solved

disable alpha caracters in ASP.NET textbox

Posted on 2009-02-17
6
Medium Priority
?
265 Views
Last Modified: 2012-05-06
is there any way i can prevent from any alpha car from being entered
0
Comment
Question by:Chris Jones
  • 3
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
aibusinesssolutions earned 2000 total points
ID: 23664995
You would use javascript.  This will only allow numbers to be entered.

If you want, you can add the attribute in the form_load function

textbox1.attributes.add("onkeypress","return isNumberKey(event)")
<SCRIPT language=Javascript>
      <!--
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
 
         return true;
      }
      //-->
   </SCRIPT>
 
<asp:TextBox id="textbox1" runat="server" onkeypress="return isNumberKey(event)" />

Open in new window

0
 
LVL 1

Author Comment

by:Chris Jones
ID: 23665025
it tells me onkeypress is not a valid attrabute?
0
 
LVL 27

Expert Comment

by:nmarun
ID: 23665040
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23665045
It's not, but it should still work... if not you can add it during runtime in the Page_Load

<asp:TextBox id="textbox1" runat="server"  />

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    textbox1.Attributes.Add("onkeypress","return isNumberKey(event)")
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 23665135
ok this works thans

aibusinesssolutions:
0
 
LVL 1

Author Closing Comment

by:Chris Jones
ID: 31548041
Thanks for the fast reply
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question