mirror of
https://github.com/pocketbase/pocketbase.git
synced 2024-11-28 18:11:17 +02:00
22 lines
511 B
Go
22 lines
511 B
Go
package validators
|
|
|
|
import (
|
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
|
)
|
|
|
|
// Compare checks whether the validated value matches another string.
|
|
//
|
|
// Example:
|
|
// 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
|
|
}
|
|
}
|