add ExceptChars validator

This commit is contained in:
Aneurin Barker Snook
2023-11-20 17:59:05 +00:00
parent 40482060ac
commit 034557c12d
2 changed files with 40 additions and 0 deletions
+12
View File
@@ -20,3 +20,15 @@ func Chars(allow string) func(string) error {
return nil
}
}
// ExceptChars validates whether a string does not contain disallowed characters.
func ExceptChars(disallow string) func(string) error {
return func(value string) error {
for _, r := range disallow {
if strings.ContainsRune(value, r) {
return ErrDisallowedChars
}
}
return nil
}
}