Sunday, October 25, 2009

Guid Validation

Here is a method where we could validate a string as a GUID using Regex pattern matching. It validates the guid case insensitively.

bool IsGuid(string Id)
{
return !string.IsNullOrEmpty(Id) && Regex.IsMatch(Id, "^[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$");
}

No comments:

Post a Comment