1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
/// <summary>
/// Determines whether the specified candidate is a valid GUID.
/// </summary>
/// <param name="candidate">The candidate.</param>
/// <returns>
/// <c>true</c> if the specified candidate is GUID; otherwise, <c>false</c>.
/// </returns>
public static bool IsValidGuid(string candidate)
{
if (string.IsNullOrEmpty(candidate))
return false;
Regex isGuid = new Regex(@"^(\{){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}$");
return isGuid.IsMatch(candidate);
}
|