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

 

 

 
 

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.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
Employers - Post Free Jobs