tui/validators/range.go

34 lines
512 B
Go
Raw Permalink Normal View History

2024-07-04 20:22:54 +01:00
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
}