Skip to content
New issue

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

How can we validate end date should be greater than start date? #25

Closed
jogiranjith opened this issue Feb 23, 2018 · 1 comment
Closed

Comments

@jogiranjith
Copy link

No description provided.

@thedevsaddam
Copy link
Owner

@jogiranjith Probably you need to access other value from http.request. But at this point (v1.9) we don't have any request object inside AddCustomRule.

We can pass the request object to custom rules for further manipulation, but we can't do this change on patch, because it'll change API and break others code. Hope, we will be able to pass the request object to the AddCustomRule for v2.0.

Note: But there is a tricky way to solve your problem, you can check the dates manually after the other validation:

v := govalidator.New(opts)
e := v.Validate()
if startDate > endDate {
    e.Add("start_date", "Start date can not be greater than end date") // this will add the error message to the validation errors
    e.Add("end_date", "Start date can not be greater than end date")
}

As 2.0 will be our next major release, you may have to wait a little time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants