Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How can restrict text in a textbox to specific Type of Text in VB.

Author: DevASP
Download Source Code : 564_txt_Alpha.zip

In this simple article you will learn that how you can restrict text in a textbox to specific Type of Text.

Simply just create New Project of console application in VB.

Drag four text box and four labels on form.

Create four global variables

 

Dim str As String

Dim str1 As String

Dim str2 As String

Dim str3 As String

Now just write code against these events

 

 

Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp

 

        TextBox1.Text = ""

        TextBox1.Text = str

 

    End Sub

 

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

 

        If e.KeyChar.IsLetter(e.KeyChar) Then

            str += e.KeyChar

        End If

 

    End Sub

 

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

 

        If e.KeyChar.IsDigit(e.KeyChar) Then

            str1 += e.KeyChar

        End If

 

    End Sub

 

    Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp

 

        TextBox2.Text = ""

        TextBox2.Text = str1

 

    End Sub

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Me.Text = "DevAsp"

        TextBox1.Text = ""

        TextBox2.Text = ""

        TextBox3.Text = ""

        TextBox4.Text = ""

 

    End Sub

 

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress

 

        If e.KeyChar.IsPunctuation(e.KeyChar) Then

            str2 += e.KeyChar

        End If

 

    End Sub

 

    Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyUp

 

        TextBox4.Text = ""

        TextBox4.Text = str2

 

    End Sub

 

    Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp

 

        TextBox3.Text = ""

        TextBox3.Text = str3

 

    End Sub

 

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress

 

        If e.KeyChar.IsSymbol(e.KeyChar) Then

            str3 += e.KeyChar

        End If

 

    End Sub

Article Comments
How can restrict text in a textbox to specific Type of Text in VB.

Posted on 4/6/2007 2:47:47 AM by Senthil Kumar

This was helpful for me.

Posted on 10/31/2008 5:17:02 AM by ParkashKaur

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How can restrict text in a textbox to specific length of words on run time in VB.

Disclaimer - Privacy
© 2002-2017 DevASP.net