NotEquals requires that the string does not equal any of the specified values
(stringsToCheck []string, errorMessage string)
| 10 | |
| 11 | // NotEquals requires that the string does not equal any of the specified values |
| 12 | func NotEquals(stringsToCheck []string, errorMessage string) survey.Validator { |
| 13 | // return a validator to perform the check |
| 14 | return func(val interface{}) error { |
| 15 | if str, ok := val.(string); ok { |
| 16 | for _, v := range stringsToCheck { |
| 17 | if str == v { |
| 18 | return fmt.Errorf("%s", errorMessage) |
| 19 | } |
| 20 | } |
| 21 | } else { |
| 22 | // otherwise we cannot convert the value into a string and cannot perform check |
| 23 | return fmt.Errorf("cannot check value on response of type %v", reflect.TypeOf(val).Name()) |
| 24 | } |
| 25 | |
| 26 | // the input is fine |
| 27 | return nil |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // IsUuid requires that the string is a valid UUID |
| 32 | func IsUuid(val interface{}) error { |
no outgoing calls