How can you check if a string is a valid GUID in vbscript? Has anyone written an IsGuid method?
I tried that one but I got a vbscript error. I'm guessing that's vb code not vbscript.
chumbawumba
2008-09-25 14:07:42
+1
A:
In VBScript you can use the RegExp object to match the string using regular expressions.
DaveK
2008-09-25 14:02:49
+1
A:
This is similar to the same question in c#. Here is the regex you will need...
^[A-Fa-f0-9]{32}$|^({|()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|))?$|^({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})$
But that is just for starters. You will also have to verify that the various parts such as the date/time are within acceptable ranges. To get an idea of just how complex it is to test for a valid GUID, look at the source code for one of the Guid constructors.
pdavis
2008-09-25 14:04:51
A:
This function might do the trick for you.
Function isGUID(byval strGUID)
if isnull(strGUID) then
isGUID = false
exit function
end if
dim regEx
set regEx = New RegExp
regEx.Pattern = Replace("{########-####-####-####-############}", "#", "[0-9,A-F,a-f]")
isGUID = regEx.Test(braces(strGUID))
set RegEx = nothing
End Function
Techek
2010-05-17 09:10:58