Test data type

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
 
S

Simon Shaw

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
 
S

Stewart Tanner

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
 
V

Van T. Dinh

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top