MCPcopy Create free account
hub / github.com/lxn/walk / Validate

Method Validate

validators.go:72–91  ·  view source on GitHub ↗
(v interface{})

Source from the content-addressed store, hash-verified

70}
71
72func (rv *RangeValidator) Validate(v interface{}) error {
73 f64 := v.(float64)
74
75 if f64 < rv.min || f64 > rv.max {
76 var msg string
77 if math.Abs(rv.min-math.Floor(rv.min)) < math.SmallestNonzeroFloat64 &&
78 math.Abs(rv.max-math.Floor(rv.max)) < math.SmallestNonzeroFloat64 {
79
80 msg = fmt.Sprintf(tr("Please enter a number from %.f to %.f.", "walk"),
81 rv.min, rv.max)
82 } else {
83 msg = fmt.Sprintf(tr("Please enter a number from %s to %s.", "walk"),
84 FormatFloatGrouped(rv.min, 2), FormatFloatGrouped(rv.max, 2))
85 }
86
87 return NewValidationError(tr("Number out of allowed range", "walk"), msg)
88 }
89
90 return nil
91}
92
93type RegexpValidator struct {
94 re *regexp.Regexp

Callers

nothing calls this directly

Calls 3

FormatFloatGroupedFunction · 0.85
NewValidationErrorFunction · 0.85
trFunction · 0.70

Tested by

no test coverage detected