merge v0.23.0-rc changes

This commit is contained in:
Gani Georgiev committed 2024-09-29 21:09:46 +03:00
1 parent ad92992324
commit 844f18cac3
753 files changed
+85107 -63362

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
package validators
import (
"regexp"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
// IsRegex checks whether the validated value is a valid regular expression pattern.
//
// Example:
//
// validation.Field(&form.Pattern, validation.By(validators.IsRegex))
func IsRegex(value any) error {
v, ok := value.(string)
if !ok {
return ErrUnsupportedValueType
}
if v == "" {
return nil // nothing to check
}
if _, err := regexp.Compile(v); err != nil {
return validation.NewError("validation_invalid_regex", err.Error())
}
return nil
}