Files
validate/chars.go
T
2023-11-19 20:27:33 +00:00

23 lines
412 B
Go

package validate
import (
"strings"
)
// Validation error.
var (
ErrDisallowedChars = NewError("contains disallowed characters")
)
// Chars validates whether a string contains only allowed characters.
func Chars(allow string) func(string) error {
return func(value string) error {
for _, r := range value {
if !strings.ContainsRune(allow, r) {
return ErrDisallowedChars
}
}
return nil
}
}