add validation error type, fix tests, add number tests
This commit is contained in:
@@ -1,20 +1,18 @@
|
||||
package validate
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Validation error.
|
||||
var (
|
||||
ErrDisallowedChars = errors.New("contains disallowed characters")
|
||||
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 {
|
||||
rs := []rune(value)
|
||||
for _, r := range rs {
|
||||
for _, r := range value {
|
||||
if !strings.ContainsRune(allow, r) {
|
||||
return ErrDisallowedChars
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user