🐛 fix(utils.go): check if hex-code starts with an #

This commit is contained in:
Siesta
2025-09-18 09:18:47 +02:00
parent c15cfdea70
commit 8085930dfe
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ func ViewColor(id int) (*models.LampState, error) {
func SetColor(id int, color string) error { func SetColor(id int, color string) error {
if !utils.IsValidHexColor(color) { if !utils.IsValidHexColor(color) {
return errors.New("invalid HEX Code: %s") return errors.New("invalid HEX Code")
} }
currentColor, err := ViewColor(id) currentColor, err := ViewColor(id)
if err != nil { if err != nil {
+1 -1
View File
@@ -26,7 +26,7 @@ func IDtoInt(id string) (int, error) {
} }
func IsValidHexColor(color string) bool { func IsValidHexColor(color string) bool {
pattern := `^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$` pattern := `^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$`
match, _ := regexp.MatchString(pattern, color) match, _ := regexp.MatchString(pattern, color)
return match return match
} }