ut "github.com/go-playground/universal-translator"
"github.com/squeeze69/codicefiscale"
+ "github.com/squeeze69/partitaiva"
)
type FormElement struct {
Options map[string]string
OptionsSort []string
Rows string
+ FileSize string
+ FileMimeType string
Disabled bool
Invisible bool
Validation string
return ok
}
+func ValidatorPIva(fl validator.FieldLevel) bool {
+ ok, _ := partitaiva.ItPartitaIva(fmt.Sprintf("%s", fl.Field()))
+
+ return ok
+}
+
func ValidatorNumeric(fl validator.FieldLevel) bool {
regThou := regexp.MustCompile("^[-+]?\\d{1,3}(.\\d{3})*(\\,\\d{1,2})?$")
regNoThou := regexp.MustCompile("^[-+]?\\d+(\\,\\d{1,2})?$")
return t
})
+ validate.RegisterTranslation("piva", trans, func(ut ut.Translator) error {
+ return ut.Add("piva", "Partita IVA non valida.", true)
+ }, func(ut ut.Translator, fe validator.FieldError) string {
+ t, _ := ut.T("piva", fe.Field())
+
+ return t
+ })
validate.RegisterTranslation("numeric", trans, func(ut ut.Translator) error {
return ut.Add("numeric", "Il campo deve contenere un numero.", true)
}, func(ut ut.Translator, fe validator.FieldError) string {
github.com/go-playground/universal-translator v0.18.0
github.com/go-playground/validator/v10 v10.11.0
github.com/squeeze69/codicefiscale v1.0.2
+ github.com/squeeze69/partitaiva v1.0.1
)
require (