コード例 #1
0
 public static bool IsValidLocalPartOfWindowsLiveID(string liveID)
 {
     if (string.IsNullOrEmpty(liveID) || !char.IsLetter(liveID[0]) || liveID[liveID.Length - 1] == '.' || liveID.IndexOf("..") >= 0 || liveID.Length > 63)
     {
         return(false);
     }
     foreach (char c in liveID)
     {
         if (!WindowsLiveIDLocalPartConstraint.IsValidCharForWindowsLiveID(c))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #2
0
        public static string RemoveInvalidPartOfWindowsLiveID(string liveID)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(liveID))
            {
                foreach (char c in liveID)
                {
                    if (stringBuilder.Length >= 63)
                    {
                        break;
                    }
                    if (WindowsLiveIDLocalPartConstraint.IsValidCharForWindowsLiveID(c) && (stringBuilder.Length != 0 || char.IsLetter(c)) && (stringBuilder.Length <= 0 || c != '.' || c != stringBuilder[stringBuilder.Length - 1]))
                    {
                        stringBuilder.Append(c);
                    }
                }
                if (stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] == '.')
                {
                    stringBuilder.Remove(stringBuilder.Length - 1, 1);
                }
            }
            return(stringBuilder.ToString());
        }