untitled

Pasted Oct 4, 2026, 2:58 PM1 file42 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/qwert001
untitled
private static string ValidateService(string value)
{
    value = value.Trim();

    if (string.IsNullOrWhiteSpace(value))
        return "EMPTY";

    // Multiple services can be separated by comma or newline
    var services = value.Split(
        new[] { ',', '\n', '\r' },
        StringSplitOptions.RemoveEmptyEntries);

    foreach (var service in services)
    {
        var item = service.Trim().ToLower();

        var match = System.Text.RegularExpressions.Regex.Match(
            item,
            @"^(tcp|udp)/(\d+)(-(\d+))?$");

        if (!match.Success)
            return $"INVALID: {service.Trim()}";

        int startPort = int.Parse(match.Groups[2].Value);

        if (startPort < 1 || startPort > 65535)
            return $"INVALID PORT: {service.Trim()}";

        if (match.Groups[4].Success)
        {
            int endPort = int.Parse(match.Groups[4].Value);

            if (endPort < 1 || endPort > 65535)
                return $"INVALID PORT: {service.Trim()}";

            if (startPort > endPort)
                return $"INVALID RANGE: {service.Trim()}";
        }
    }

    return "VALID SERVICE";
}

1,140 chars · codepastes.com