Posts

Showing posts from January, 2010

Validating a Guid in C#

Oftentimes you find a need to validate if a string is a valid Guid or not. Luckily for us .net offers some excellent regular expression tools. I've found the best way to do this is to place a small static function in a helper class that validates a string passed in using a regular expression. All regular expression stuff is location in the using System.Text.RegularExpressions namespace. So in some class simply call use the following code: /// <summary> /// Determines whether the specified string is GUID. /// </summary> /// <param name="guid">The GUID.</param> /// <returns> /// <c>true</c> if the specified string is GUID; otherwise, <c>false</c>. /// </returns> public static bool IsGuid( String guid ) { if( guid != null ) { return Regex.IsMatch( guid, @"^(\{){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

First post of the new year

Happy new year to everyone! I hope this year brings everyone great health, wealth, and the best possible in everything you strive towards. Normally I post a lot of code to this blog but sometimes I have interesting non code info I like to share. Today is one of those posts. I read a lot of code sites and decided to share the ones I love to read the most with you. The Old New Thing This is my favorite blog an d is run by Raymond Chan of Microsoft. He has a lot of really interesting posts about programming, technology, science, and some great insights into Microsoft and why certain things are the way they are. It's not all code all the time but it's fun to read. Joel on Software Joel on Software, another excellent blog that I think focuses more on the high level aspects of programming and less on the low level in the weeds day to day programming kind of tasks. Still tons of cool and great info to read. Coding Horror Coding Horror I think is more a general programm