Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 29th, 2005, 09:26 PM
Registered User
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default [:D]Simple Method of Validating text boxes[:D]

Hi ,

I am new to VB myself but I have a vague idea as to how you can validate text fields for numerics/alpha numerics. Ill give you the code to validate for characters. Im not sure about how to validate an email address.

one can validate a text field using the KEYDOWN method of the text box to check for the ASCII codes of each Key which is pressed while typing in the text box. heres the code.

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

'De-Comment the next line to get ascii code of keys
'MsgBox "Ascii code of the key you pressed is " & KeyCode


'if user presses the shift,caps lock , backspace ,
'space,enter or the delete key then ignore check

If KeyCode = 20 Or KeyCode = 16 Or KeyCode = 8 Or KeyCode = 32 Or KeyCode = 13 Or KeyCode = 46 Then
Exit Sub
End If

'If user presses anything other than a character ie. Ascii code 65-90 then error
If KeyCode < 65 Or KeyCode > 90 Then
MsgBox "Error! only characters"
Text1.Text = ""
End If

End Sub


if anyone knows how to validate an Email address please enlighten me :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating a text box maitias C# 2005 2 March 25th, 2007 01:52 AM
Validating Text in JText javanewbie05 Java GUI 3 June 23rd, 2005 08:35 AM
Validating Template Text box aleahy BOOK: Beginning ASP.NET 1.0 0 November 11th, 2003 11:22 AM
validating rich text field for attachment Mimi Javascript How-To 4 August 25th, 2003 03:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.