Wednesday, September 10, 2008

CheckValidGuid(string strGuid)

Code snippet to check if the entered string is a valid Guid or not.


public static bool IsValidGuid(string value)
{
if (value == null)
throw new ArgumentNullException("value", "Invalid null value supplied");
return Regex.IsMatch(value, @"^(\{){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}$", RegexOptions.CultureInvariant);
}

Happy Coding !!!

No comments: