private static bool GuidFormatValidate(string guid, string format = "U") { if ("U".Equals(format)) { format = GuidDate.DetectedFormat(guid); } string regexp = GuidDate.getGuidFormat(format).Replace("0", "[a-f0-9]") .Replace("{", "\\{") .Replace("}", "\\}") .Replace("(", "\\(") .Replace(")", "\\)"); return(Regex.Match(guid, "" + regexp + "", RegexOptions.IgnoreCase).Success&& !"U".Equals(format)); }
/// <summary> /// Valida que el checksun del GUID sea correcto /// </summary> /// <param name="guid">Guid</param> /// <param name="crcKey">Key para calcular el checksun</param> /// <returns>Indica si el checksun es correcto</returns> public static bool Validate(string guid, string format = "U", string crcKey = GuidDate.DEFAULT_CRCKEY) { if ("U".Equals(format)) { format = GuidDate.DetectedFormat(guid); } if (!GuidDate.GuidFormatValidate(guid, format)) { return(false); } string guidAux = new Regex(@"[^0-9a-fA-F]").Replace(guid, ""); string guidOrigin = guidAux.Substring(2, guidAux.Length - 2); string guidCRC = guidAux.Substring(0, 2); string crc = CreateCRC(guidOrigin, crcKey); return(crc == guidCRC); }