ValidateIPAddress validates if the given value is a correctly formatted IP address, and returns the value in normalized form. Leading and trailing whitespace is allowed, but it does not allow IPv6 addresses surrounded by square brackets ("[::1]"). Refer to [net.ParseIP] for accepted formats.
(val string)
| 186 | // |
| 187 | // Refer to [net.ParseIP] for accepted formats. |
| 188 | func ValidateIPAddress(val string) (string, error) { |
| 189 | if ip := net.ParseIP(strings.TrimSpace(val)); ip != nil { |
| 190 | return ip.String(), nil |
| 191 | } |
| 192 | return "", fmt.Errorf("IP address is not correctly formatted: %s", val) |
| 193 | } |
| 194 | |
| 195 | // ValidateMACAddress validates a MAC address. |
| 196 | // |
searching dependent graphs…