Jump to content

Validating fields in VB ?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
jashsayani

jashsayani

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
I have just made a small application in VB6 and would like to implement data validation for a few fields. Like the user can only enter a number in the Telephone number field.

How can this be implemented ?

Thanks.

#2
anglina

anglina

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
post code or lookup some tuts first.
imacooknotachef.com
Food/Photo Blog

#3
thanasis2028

thanasis2028

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Here is how you can validate a textbox:
  Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.A Then
            e.SuppressKeyPress = False
        Else
            e.SuppressKeyPress = True
        End If
    End Sub
This code is used in the eydown event of a textbox and in this way the only key to be accepted is "a". With some more work you can validate whatever you want.
My software company:Porosis Software
Games: Terrantula
Apps: Mathanasis, ColorGrabber (New!)

#4
anglina

anglina

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Another way to do it is by using Regular Expressions

http://www.regular-e...nfo/dotnet.html

Edited by anglina, 13 April 2010 - 03:42 PM.
Code was incorrect

imacooknotachef.com
Food/Photo Blog