2008-09-25 22 views

回答

2

这与same question in c#相似。这是您需要的正则表达式...

^[A-Fa-f0-9] {32} $ | ^({|()?[A-Fa-f0-9] {8} - ( [A-发f0-9] {4} - ){3} [A-发f0-9] {12}(} |?))$ | ^({)是0xA-发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}(}})$

但这仅仅是为了初学者。您还必须验证诸如日期/时间等各个部分是否在可接受的范围内。要想知道测试一个有效的GUID有多复杂,请查看其中一个Guid构造函数的源代码。

+0

文字括号需要转义。例如,第二个子表达式应该是`| {({| \()[A-Fa-f0-9] {8} - ([A-Fa-f0-9] {4} - ){3} [ A-Fa-f0-9] {12}(} | \))?$`而不是`| ^({|()?[A-Fa-f0-9] {8} - ([A-Fa- f0-9] {4} - ){3} [A-发f0-9] {12}(} |))$`?。 – Heinzi 2012-02-21 09:24:38

1

请参阅Check a GUID

+1

我想,一个,但我有一个VBScript错误。我猜这是vb代码不是vbscript。 – chumbawumba 2008-09-25 14:07:42

+0

VBScript不支持`Like` – AutomatedChaos 2012-09-07 15:49:13

1

在VBScript中,您可以使用RegExp对象使用正则表达式匹配字符串。

-3

还有另一种解决方案:

try 
{ 
    Guid g = new Guid(stringGuid); 
    safeUseGuid(stringGuid); //this statement will execute only if guid is correct 
}catch(Exception){} 
1

Techek的功能并没有在传统的ASP(VBScript)作为我的工作。由于某种奇怪的原因,它总是返回True。通过一些小的改变它确实有效。见下面

Function isGUID(byval strGUID) 
    if isnull(strGUID) then 
    isGUID = false 
    exit function 
    end if 
    dim regEx 
    set regEx = New RegExp 
    regEx.Pattern = "{[0-9A-Fa-f-]+}" 
    isGUID = regEx.Test(strGUID) 
    set RegEx = nothing 
End Function 
1

此功能工作在传统的ASP:

Function isGUID(byval strGUID) 
     if isnull(strGUID) then 
     isGUID = false 
     exit function 
     end if 
     dim regEx 
     set regEx = New RegExp 
     regEx.Pattern = "^({|\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\))?$" 
     isGUID = regEx.Test(strGUID) 
     set RegEx = nothing 
End Function