Allow Only Digits in Text Box

Downloads:1092 Bookmark this code Bookmark and Share
Rank : 3.75/5
Rated by : 8 user(s)
Developer:Bilal Yousaf  |   5 submission(s)
Date Uploaded:November 13,2007
Level:Intermediate
Size: 0 Bytes
Category:VB.Net -> Controls and Forms
Developer Says:

Allow only digits in text box just call this function from the keypress event of the specific textbox

Public Function OnlyDigitsOnKeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Try
            If System.Char.IsDigit(e.KeyChar) = False And e.KeyChar <> Microsoft.VisualBasic.Chr(8) And e.KeyChar <> Microsoft.VisualBasic.Chr(46) Or (InStr(sender.text, ".") > 0 And e.KeyChar = Microsoft.VisualBasic.Chr(46)) Then
                e.Handled = True
            End If
        Catch ex As Exception
            Common.ErrorHandler(ex)
        End Try
End Function

The above code was highlighted with Neat Highlighter


User Reviews
There are no user reviews on this code
Leave a Comment
Age (Required, will not be shown)
Name
Email (Required, will not be shown)
Website (Optional, starting with http://)
 
Rate this code
Poor   1 2 3 4 5   Outstanding
Are you human ?

Enter the code shown above