IsGuid

public static bool IsGuid(this string value)
{
	if (string.IsNullOrEmpty(value))
	{
		return false;
	}

	const string pattern = @"^(\{{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 Regex.IsMatch(value, pattern);
}
Example:
string testValue = "{CA761232-ED42-11CE-BACD-00AA0057B223}";
bool isGuid = testValue.IsGuid();

Description

Validate if a String contains a GUID in groups of 8, 4, 4, 4, and 12 digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses.

Details

Double click on the code to select all.

 

;