Test data type

  • Thread starter Thread starter John
  • Start date Start date
J

John

I want to test a text string, which if it exists will be
three characters long. If the first two characters are
letters and the last is a number then the result should be
true. Any help with this problem.
Thanks
 
Lots of ways of doing this - my quick 'n' clumsy stab:

public function IsItValid(strInput as string)
Dim strString as string
IsItValid=True
strString=nz(strInput)
if len(strString)<>3 OR _
left(strString,1)<"A" OR _
left(strString,1)>"z" OR _
mid(strString,2,1)<"A" OR _
mid(strString,2,1)>"z" OR _
right(strString,1)<"0" OR _
right(strString,1)>"9" then IsItValid=False
end function
 
Public Function myCheck(mystr As String) As Boolean
myCheck = True
If IsNumeric(Left(mystr, 1)) Or IsNumeric(Mid(mystr, 2, 1)) Or Not
IsNumeric(Mid(mystr, 3, 1)) Then
myCheck = False
End If
End Function
 
MyString$ = "AB2"
?Eval("'" & MyString & "'" & " Like '[a-z][a-z][0-9]'")
-1 (True)

MyString$ = "222"
?Eval("'" & MyString & "'" & " Like '[a-z][a-z][0-9]'")
0 (False)
 
Back
Top