验证给定字符串是否是合法的Guid
/// <summary>
/// 验证给定字符串是否是合法的Guid
/// </summary>
/// <param name="strToValidate">要验证的字符串</param>
/// <returns>true/false</returns>
//======== C# ========//
public static bool IsGuid(string strToValidate)
{
bool isGuid = false;
string strRegexPatten = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\"
+@"-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$";
if (strToValidate != null && !strToValidate.Equals(""))
{
isGuid = Regex.IsMatch(strToValidate,strRegexPatten);
}
return isGuid;
}
/// 验证给定字符串是否是合法的Guid
/// </summary>
/// <param name="strToValidate">要验证的字符串</param>
/// <returns>true/false</returns>
//======== C# ========//
public static bool IsGuid(string strToValidate)
{
bool isGuid = false;
string strRegexPatten = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\"
+@"-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$";
if (strToValidate != null && !strToValidate.Equals(""))
{
isGuid = Regex.IsMatch(strToValidate,strRegexPatten);
}
return isGuid;
}
'//======== VB ========//
Public Shared Function IsGuid(ByVal strToValidate As String) As Boolean
IsGuid = False
Dim strRegexPatten As String = "^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\" _
& "-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$"
If strToValidate <> Nothing And Not strToValidate.Equals("") Then
isGuid = Regex.IsMatch(strToValidate, strRegexPatten)
End If
Return isGuid
End Function
Public Shared Function IsGuid(ByVal strToValidate As String) As Boolean
IsGuid = False
Dim strRegexPatten As String = "^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\" _
& "-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$"
If strToValidate <> Nothing And Not strToValidate.Equals("") Then
isGuid = Regex.IsMatch(strToValidate, strRegexPatten)
End If
Return isGuid
End Function