feat: birthday validation integrated into profile
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"easywish/config"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
@@ -55,6 +56,22 @@ func GetCustomHandlers() []CustomValidatorHandler {
|
||||
return regexp.MustCompile(`^.{1,512}$`).MatchString(username)
|
||||
}},
|
||||
|
||||
{
|
||||
FieldName: "birthday_unix_milli",
|
||||
Function: func(fl validator.FieldLevel) bool {
|
||||
|
||||
timestamp := fl.Field().Int()
|
||||
date := time.UnixMilli(timestamp)
|
||||
currentDate := time.Now()
|
||||
|
||||
age := currentDate.Year() - date.Year()
|
||||
if currentDate.YearDay() < date.YearDay() {
|
||||
age--
|
||||
}
|
||||
|
||||
return age >= 0 && age <= 122
|
||||
}},
|
||||
|
||||
{
|
||||
FieldName: "color_hex",
|
||||
Function: func(fl validator.FieldLevel) bool {
|
||||
|
||||
Reference in New Issue
Block a user