Allow only Numeric ????????

javascript United States
  • 16 years ago

    hi,
     
    I have a textbox, in that i need to enter only numeric value. how can i do that in VB.Net. ?

  • 16 years ago
  • 16 years ago
    here is a simple way to accept only numeric enteries...

    Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
           If (e.KeyChar.IsDigit(e.KeyChar)) Then
               e.Handled = False
           Else
               e.Handled = True
           End If
       End Sub

  • 16 years ago

    Thanks a lot guys....but i could not able to modify .. so i added one more line to malathirs's code


    Private Sub TxtDestKeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Txt_Dest.KeyPress


           If e.KeyChar.IsDigit(e.KeyChar) Then
               e.Handled = False
           ElseIf Asc(e.KeyChar) = 8 Then
               e.Handled = False
           Else
               e.Handled = True
           End If


    thanks,
    Kari

  • 16 years ago

    Does this code prevent the entry of special characters?


    here is a simple way to accept only numeric enteries...


    Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
          If (e.KeyChar.IsDigit(e.KeyChar)) Then
              e.Handled = False
          Else
              e.Handled = True
          End If
      End Sub


  • 16 years ago

    Does this code prevent the entry of special characters?


  • 16 years ago

    Does this code prevent the entry of special characters? and how is it different form IsNum?


  • 16 years ago
    Does this code prevent the entry of special characters? and how is it different form IsNum?

    server error message.
  • 12 years ago

    Guys, You should make use of the power of javascript to allow only numeric in textboxes..

    http://dotnetsoldier.blogspot.com/2008/07/javascript-to-accept-only-numeric.html

    Thanks, Ziyad

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Weeks of coding can save you hours of planning.”