Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Restrict non numeric characters in a text box

sgeelksgeelk Member Posts: 5

I want to restrict users entering non numeric characters in a text box
How can I do this?
If there is any code sample please answer or email Ill be very glad
Thank you


Comments

  • vbjayvbjay Member Posts: 7
    :
    : I want to restrict users entering non numeric characters in a text box
    : How can I do this?
    : If there is any code sample please answer or email Ill be very glad
    : Thank you
    :
    :
    :
    in the Keypress event of the textbox test to see if the key was a numeric key if not then set e.handled to true.
  • btsebbtseb Member Posts: 67
    : :
    : : I want to restrict users entering non numeric characters in a text box
    : : How can I do this?
    : : If there is any code sample please answer or email Ill be very glad
    : : Thank you
    : :
    : :
    : :
    : in the Keypress event of the textbox test to see if the key was a numeric key if not then set e.handled to true.
    :
    [red]Here is a class for numeric textbox:

    Public Class NumericTextBox
    Inherits System.Windows.Forms.TextBox


    Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
    If Char.IsDigit(e.KeyChar) _
    OrElse e.KeyChar = ","c _
    OrElse e.KeyChar = "."c OrElse _
    Char.GetUnicodeCategory(e.KeyChar) _
    = Globalization.UnicodeCategory.Control OrElse _
    Char.GetUnicodeCategory(e.KeyChar) _
    = Globalization.UnicodeCategory.CurrencySymbol _
    OrElse Char.GetUnicodeCategory(e.KeyChar) _
    = Globalization.UnicodeCategory.Format Then

    e.Handled = False

    Else
    e.Handled = True

    End If
    End Sub
    End Class[/red]

Sign In or Register to comment.