Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

String Extension Method: IsGuid()

Modified: 2008/11/19 11:51 by arjan - Categorized as: Csharp, Extension Method


I wrote an extension method for the string type. With this method you can check if an string is an Guid. The method returns a Bool.

C#:
public static class StringExtensions
{
  public static bool IsGuid(this string input)
  {
    return Regex.Match(input, @"^ (?:\{)? (?<GUID> [0-9a-f]{8} \- [0-9a-f]{4} \- [0-9a-f]{4} \- [0-9a-f]{4} \- [0-9a-f]{12} ) (?:\})? $", 
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled).Success;
  }
} 

Source: blog.newguid.net

 © Evident Interactive BV