2022-07-07 00:19:05 +03:00
|
|
|
package validators
|
|
|
|
|
|
|
|
import (
|
|
|
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Compare checks whether the validated value matches another string.
|
|
|
|
//
|
|
|
|
// Example:
|
2023-02-23 21:51:42 +02:00
|
|
|
//
|
2022-07-07 00:19:05 +03:00
|
|
|
// validation.Field(&form.PasswordConfirm, validation.By(validators.Compare(form.Password)))
|
|
|
|
func Compare(valueToCompare string) validation.RuleFunc {
|
|
|
|
return func(value any) error {
|
|
|
|
v, _ := value.(string)
|
|
|
|
|
|
|
|
if v != valueToCompare {
|
|
|
|
return validation.NewError("validation_values_mismatch", "Values don't match.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|