tui/validators/range.go
2024-07-04 15:22:54 -04:00

33 lines
512 B
Go

package validators
import (
"fmt"
"strconv"
)
func Range(min int, max int) TextInputValidator {
return TextInputRange{
min: min,
max: max,
}
}
type TextInputRange struct {
min int
max int
}
func (d TextInputRange) Notice() string {
return fmt.Sprintf("Valid values: (%d - %d)", d.min, d.max)
}
func (d TextInputRange) ValidationFunc(input string) bool {
portNum, err := strconv.Atoi(input)
if err != nil {
return false
}
if portNum > 65535 || portNum < 1 {
return false
}
return true
}