Blog

Numeric Text box

Posted by Ankur Gupta Blogs | Active Directory in VB.NET Jun 02, 2010
How can we put only numbers in Text box control?

 

Put the following code in Textbox Ker Press event.

This code will allow only Numbers in the Textbox

Dim isBackSpace As Boolean = False

        Dim isKey As Boolean = [Char].IsDigit(e.KeyChar)

        If Asc(e.KeyChar) = 8 Then

            isBackSpace = True

        End If

        If Not isKey AndAlso Not isBackSpace Then

            e.Handled = True

        End If

If you want to put decimal also in the text box the use the following code.

Dim txtbox As TextBox

            txtbox = sender

            Dim isBackSpace As Boolean = False

            Dim isKey As Boolean = [Char].IsDigit(e.KeyChar)

            If Asc(e.KeyChar) = 8 Then

                isBackSpace = True

            End If

            If Not isKey AndAlso Not isBackSpace AndAlso txtbox.Text.Contains(".") Then

                e.Handled = True

            End If

 

 

 
 

post comment
     

we can also use MaskTextBox control

Posted by Hirendra Sisodiya Jun 30, 2010
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.