|
-
Nov 4th, 2000, 09:28 PM
#1
Thread Starter
Frenzied Member
Hi,
I have a text box whereby I need to check to make sure that the user typed in a minimum pattern requirement.
The text box needs to at the minimum contain 1 character (either alpha or numeric) followed by a / and then followed by at least 1 more character (alpha or numeric). So, at the minimum, the text needs to look like:
a/a or 1/1 or A/a or 4/5 etc...
but can also look like:
asdfkadgjakldf/asdfadjfkladfj/asdfajdfkj etc...
just as long as there is at least 1 forward slash immediately preceded by character and followed by a character..
any help would be apprecaited..
dan
-
Nov 4th, 2000, 10:24 PM
#2
Fanatic Member
This may not be the best solution, but it works:
Code:
Option Explicit
Private Sub Command1_Click()
MsgBox blValidateText(Text1.Text)
End Sub
Private Function blValidateText(str As String) As Boolean
Dim stLeft As String
Dim stRight As String
Dim I As Integer
Dim strPrev As String: strPrev = ""
If InStr(1, str, "/") = 0 Or Len(str) < 3 Or Left(str, 1) = "/" Or Right(str, 1) = "/" Then
blValidateText = False
Exit Function '//Exit function (no / so there is no point in checking any further)
End If
'//Get characters preceding and following the FIRST forward slash
stLeft = Mid(str, InStr(1, str, "/") - 1, 1)
stRight = Mid(str, InStr(1, str, "/") + 1, 1)
For I = 1 To Len(str) '//We don't want two or more / in a row
'//If there are two / in a row then exit the function
If Mid(str, I, 1) = "/" And strPrev = "/" Then
blValidateText = False
Exit Function
End If
strPrev = Mid(str, I, 1)
Next I
'//Check if the character preceding the "/" is a valid character (letter or a number)
If (UCase(stLeft) < "A" Or UCase(stLeft) > "Z") And Not IsNumeric(stLeft) Then
blValidateText = False
Exit Function
End If
'//Check if the character following the "/" is a valid character (letter or a number)
If (UCase(stRight) < "A" Or UCase(stRight) > "Z") And Not IsNumeric(stRight) Then
blValidateText = False
Exit Function
End If
blValidateText = True
End Function
-
Nov 4th, 2000, 10:28 PM
#3
Addicted Member
Here it is
This may not be the most effiecient code but it should work for you! Just add a textbox and a command button.
Code:
Private Sub Command1_Click()
'-Initial check to see if a character even exists
If Len(Text1.Text) < 1 Then
Exit Sub
End If
'-Put text into variable
Dim tmpText As String
tmpText = Text1
'-Search for /
Dim BackSlashPos As Integer
BackSlashPos = InStr(1, tmpText, "/")
If BackSlashPos = 0 Then
MsgBox "Missing Backslash: a/a"
Else
If Not Len(tmpText) > BackSlashPos Then
MsgBox "No Character After Backslash: a/a"
Else
MsgBox "Correct Form!"
End If
End If
End Sub
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
|