Testing formats

Rob.Mills

Registered User.
Local time
Today, 06:58
Joined
Aug 29, 2002
Messages
871
Does anyone know how to create a procedure that will take a string and test to see if it fits a certain format?
 
If IsDate or IsNumeric or IsNull or IsArray functions are not enough, try using a MID() function to challenge a specific character location in the string to see if it meets a certain criteria.

Code:
dim blnValid as Boolean
blnValid = True
dim strSample as string
strSample = "12:34"
if Not isnumeric(mid(strSample,1)) then blnValid = False
if Not isnumeric(mid(strSample,2)) then blnValid = False
if mid(strSample,3)<>":" then blnValid = False
if Not isnumeric(mid(strSample,4)) then blnValid = False
if Not isnumeric(mid(strSample,5)) then blnValid = False
msgbox "Is Valid: " & blnValid
The output of the above is True.
Code:
dim blnValid as Boolean
blnValid = True
dim strSample as string
strSample = "12:xx"
if Not isnumeric(mid(strSample,1)) then blnValid = False
if Not isnumeric(mid(strSample,2)) then blnValid = False
if mid(strSample,3)<>":" then blnValid = False
if Not isnumeric(mid(strSample,4)) then blnValid = False
if Not isnumeric(mid(strSample,5)) then blnValid = False
msgbox "Is Valid: " & blnValid
The ouput of the above is False.
 
Thanks! That's what I was looking for.
 

Users who are viewing this thread

Back
Top Bottom