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.
Validating fields in VB ?
Started by jashsayani, Apr 22 2009 02:30 PM
3 replies to this topic
#1
Posted 22 April 2009 - 02:30 PM
|
|
|
#2
Posted 11 April 2010 - 10:44 PM
#3
Posted 13 April 2010 - 08:34 AM
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.
#4
Posted 13 April 2010 - 03:35 PM
Another way to do it is by using Regular Expressions
http://www.regular-e...nfo/dotnet.html
http://www.regular-e...nfo/dotnet.html
Edited by anglina, 13 April 2010 - 03:42 PM.
Code was incorrect
imacooknotachef.com
Food/Photo Blog
Food/Photo Blog


Sign In
Create Account


Back to top









