integer input in textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mhtkht
    New Member
    • Jan 2007
    • 1

    #1

    integer input in textbox

    hello every1,
    Im a new member.plz help me out.i want a textbox to take only numbers as its input. no character or symbol other than an integer should b entered .
    isnumeric will check whether the entered value is a number or not.but i want to enter only numbers.it shld prompt if a user tries entering any character or something..plz help me its urgent...
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,
    On a keypress of textbox write this code

    Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As System.Windows. Forms.KeyPressE ventArgs) Handles TextBox1.KeyPre ss
    if( e.KeyChar.IsDig it = False) then
    e.KeyChar=""
    end if
    End Sub


    Shweta

    Comment

    • knychtell
      New Member
      • Jan 2007
      • 66

      #3
      hi i hope you still need this one,

      in txtbox1 view code:

      if isnumeric(txtbo x1.text) then
      messagebox.show ("Please enter a valid format")
      txtbox1.focus
      txtbox1.text="" ' to delete or remove the current character entered by the user,

      Comment

      • moiashvin
        New Member
        • Sep 2006
        • 16

        #4
        Hi,

        i think you should also think whether the user will be able to enter backspace or not.

        In the key press event handler, you can check to see if (e.KeyChar != (char)8)...

        Cheers

        Comment

        Working...