govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

not support for range now?

Open chenjie4255 opened this issue 6 years ago • 8 comments

type Item struct {
	Bt int `valid:"range(1|100)"`
}

func main() {
	t := Item{-1}
	ok, err := govalidator.ValidateStruct(t)
	fmt.Println(ok, err)
}

output:Bt: Validator range(1|100) doesn't support kind int;

chenjie4255 avatar Sep 08 '17 06:09 chenjie4255

There is a support for InRange but it works only with float numbers. https://github.com/asaskevich/govalidator/blob/aa5cce4a76edb1a5acecab1870c17abbffb5419e/numerics.go#L42 I think there must be different functions for float and decimal numbers e.g. InRangeFloat32 and InRangeInt

asaskevich avatar Nov 03 '17 19:11 asaskevich

Submitted pull request #239

jasonlam604 avatar Nov 07 '17 05:11 jasonlam604

Merged, thanks!

asaskevich avatar Nov 09 '17 09:11 asaskevich

But there is no definition of functions to use them in struct tags, will be resolved

asaskevich avatar Nov 09 '17 09:11 asaskevich

Do I get it correctly that I can't do the simplest thing - validate an int* field in struct against a range - with govalidator? :)

blind-oracle avatar Mar 13 '18 12:03 blind-oracle

I've created a PR with a quick & dirty fix: https://github.com/asaskevich/govalidator/pull/263

blind-oracle avatar Mar 13 '18 14:03 blind-oracle

Please close the issue. It's fixed. @asaskevich

RajatVaryani avatar Sep 22 '18 11:09 RajatVaryani

Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev