mirror of
https://github.com/Kyren223/eko.git
synced 2025-09-12 00:18:23 +00:00
24 lines
449 B
Go
24 lines
449 B
Go
package api
|
|
|
|
import "strings"
|
|
|
|
const hex = "0123456789abcdefABCDEF"
|
|
|
|
func isValidHexColor(color string) (bool, string) {
|
|
if len(color) != 7 {
|
|
return false, "color must be hex with length of 7"
|
|
}
|
|
|
|
if color[0] != '#' {
|
|
return false, "color must start with '#'"
|
|
}
|
|
|
|
for _, c := range color {
|
|
if !strings.ContainsRune(hex, c) {
|
|
return false, "color must start with '#' and contain exactly 6 digits 0-9, a-f, A-F"
|
|
}
|
|
}
|
|
|
|
return true, ""
|
|
}
|