Home
Manage Your Code
Snippet: IsGuid Function (C#)
Title: IsGuid Function Language: C#
Description: returns bool if a string in the proper format for a GUID, using a regular expression. Views: 253
Author: Steve Vasquez Date Added: 4/22/2008
Copy Code  
1public static bool IsGUID(string expression)
2{
3    if (expression != null)
4    {
5        Regex guidRegEx = 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})$");
6
7        return guidRegEx.IsMatch(expression);
8    }
9    return false;
10}
Usage
check if a string is a valid formatted GUID