We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When validating a field with rule "required" and "numeric", when the value of 0 is provided, required validation error is trigered.
Go version: 1.9 Framework: echo Here is an example
type serviceRequest struct { Owner string json:"owner" Service int json:"service" Operation string json:"operation" AgentTransaction string json:"ati" }
json:"owner"
json:"service"
json:"operation"
json:"ati"
func AgentServiceAction(c echo.Context) (err error) {
var structure serviceRequest rules := govalidator.MapData{ "owner": []string{"required", "between:10,16"}, "service": []string{"required", "numeric"}, "operation": []string{"required", "in:start,confirm,check"}, "ati": []string{"required", "alpha_num", "max:64", "min:1"}, } opts := govalidator.Options{ Request: c.Request(), // request object Data: &structure, //Structure to validate Rules: rules, // rules map } v := govalidator.New(opts) e := v.ValidateJSON() fmt.Println(v) fmt.Println(e) verr := map[string]interface{}{"validationError": e} return c.JSON(200, response.JsonResponse{ Code: 300, Message: "All good!", Data: verr, })
}
{ "ati":"324t5fc45w6bh6r7unr758rtinr67", "operation":"start", "owner":"871029399119", "service":0 }
{ "code": 300, "success": false, "message": "All good!", "data": { "validationError": { "service": [ "The service field is required" ] } } }
The text was updated successfully, but these errors were encountered:
Is there an ETA on this?
Sorry, something went wrong.
@Entrio I am working on this in fix/numeric-field branch. Hopefully, it'll complete by next week.
@Entrio Here is a fix. Hope it'll work fine.
thedevsaddam
No branches or pull requests
When validating a field with rule "required" and "numeric", when the value of 0 is provided, required validation error is trigered.
Go version: 1.9
Framework: echo
Here is an example
Json struct
Here is the request handling function
}
Post data:
The received response:
The text was updated successfully, but these errors were encountered: