Blog

Numeric Text box

Jun 02, 2010 Blogs | Active Directory in VB.NET
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

 

 

 
 

Ankur Gupta

I am Ankur Gupta Working in MNC as a sr. software engg. My major area of experiance in Accounting and CRM with  C#,VB.Net,WCF,ASP.net languages.

  • 273rank
  • 518K readers
  • 1times
COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs