|
-
Feb 25th, 2006, 01:36 PM
#1
Thread Starter
Member
[RESOLVED] Validating a textbox
How to validate a textbox on Lost Focus event so that only alphabetic characers are possible?of eq if the field is Name
-
Feb 25th, 2006, 01:50 PM
#2
Re: Validating a textbox
U can use this code in the keypress event
Copy the following code in the keypress event
dim strvalid as string
strvalid="abcdedfghijkilmnopqrstuvwxyzABCEDEFGHIJKILMNOPQRSTUVWXYZ"
If InStr(strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
Hopes it helps u
-
Feb 25th, 2006, 01:54 PM
#3
Re: Validating a textbox
First you could catch the key pressed in the keypress event and if its a number then cancel it but that still doesnt stop them pasting a number in so try looping through the textbox in the validate event
VB Code:
Private Sub Text1_Validate(Cancel As Boolean)
Dim i As Integer
For i = 1 To Len(Text1.Text)
If IsNumeric(Mid$(Text1.Text, i, 1)) Then
MsgBox "No Numbers Please"
Cancel = True
Exit For
End If
Next i
End Sub
casey.
-
Feb 25th, 2006, 02:04 PM
#4
Thread Starter
Member
Re: Validating a textbox
Thanx,that was helpful, but how to ignore values like ';./,]{}_+| and have an error message come up if these values are input?
-
Feb 25th, 2006, 02:35 PM
#5
Thread Starter
Member
-
Feb 25th, 2006, 02:36 PM
#6
Re: Validating a textbox
Check each Ascii character.
VB Code:
Dim i As Integer
For i = 1 To Len(Text1.Text)
Select Case Asc(Mid$(Text1.Text, i, 1))
Case 65 To 90 'A - Z
Case 97 To 122 'a - z
Case Else
MsgBox "Invalid Character " & Mid$(Text1.Text, i, 1)
Cancel = True
Exit For
End Select
Next
-
Feb 25th, 2006, 02:45 PM
#7
Thread Starter
Member
Re: Validating a textbox
Wow,thank you soo much!!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|