Fengzhimei@Dot.Net
Designing My Colorful Dream
     In this implementationtime,I just show you a simple way to validate a Guid.
1/// <summary>
2/// 验证给定字符串是否是合法的Guid
3/// </summary>
4/// <param name="strToValidate">要验证的字符串</param>
5/// <returns>true/false</returns>
6public static bool IsGuid(string strToValidate)
7{
8 bool isGuid = false;
9 string strRegexPatten = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\"
10         +@"-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$";
11 if (strToValidate != null && !strToValidate.Equals(""))
12 {
13  isGuid = Regex.IsMatch(strToValidate,strRegexPatten);
14 }
15 return isGuid;
16}
posted on 2004-04-17 20:07  fengzhimei  阅读(991)  评论(0编辑  收藏  举报