Feedback

MD5 String validieren

Sprache: C#

Diese Methode validiert einen MD5 String. Sind die einzelnen Hexwerte mit einem – getrennt, kann folgender Pattern verwendet werden: ^([a-fA-F0-9]{2}-){15}[a-fA-F0-9]{2}$ Benötigter Namespace: System.Text.RegularExpressions
/// <summary>
/// Determines whether [is valid M d5] [the specified candidate].
/// </summary>
/// <param name="candidate">The candidate.</param>
/// <returns>
/// 	<c>true</c> if [is valid M d5] [the specified candidate]; otherwise, <c>false</c>.
/// </returns>
public static bool IsValidMD5(string candidate)
{
    if (string.IsNullOrEmpty(candidate))
        return false;

    Regex isMD5 = new Regex(@"^([a-fA-F0-9]){32}$");
    return isMD5.IsMatch(candidate);
}
/// <summary>
/// Determines whether [is valid M d5] [the specified candidate].
/// </summary>
/// <param name="candidate">The candidate.</param>
/// <returns>
/// 	<c>true</c> if [is valid M d5] [the specified candidate]; otherwise, <c>false</c>.
/// </returns>
public static bool IsValidMD5(string candidate)
{
    if (string.IsNullOrEmpty(candidate))
        return false;

    Regex isMD5 = new Regex(@"^([a-fA-F0-9]){32}$");
    return isMD5.IsMatch(candidate);
}

1 Kommentar