Skip to content

Commit

Permalink
latin validator
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Sep 3, 2024
1 parent 177dc04 commit cf3fb85
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/validation/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ var DBValidators = map[*regexp.Regexp]func(match []string, value *generic.Value,

var Validators = map[*regexp.Regexp]func(match []string, value *generic.Value) error{
regexp.MustCompile("^text$"): textValidator,
regexp.MustCompile("^name$"): nameValidator,
regexp.MustCompile("^alpha$"): alphaValidator,
regexp.MustCompile("^latin$"): latinValidator,
regexp.MustCompile("^name$"): nameValidator,
regexp.MustCompile("^digit$"): digitValidator,
regexp.MustCompile("^alphanumeric$"): alphaNumericValidator,
Expand All @@ -45,6 +47,15 @@ var Validators = map[*regexp.Regexp]func(match []string, value *generic.Value) e
regexp.MustCompile(`^date$`): dateValidator,
}

func latinValidator(match []string, value *generic.Value) error {
var v = regexp.MustCompile(`^\p{L}*$`)
matchString := v.MatchString(value.String())
if !matchString {
return fmt.Errorf("is not latin")
}
return nil
}

var enumRegex = regexp.MustCompile(`(?m)enum\(([^)]+)\)`)
var enumBodyRegex = regexp.MustCompile(`(?m)'([^']*)'`)

Expand Down Expand Up @@ -402,7 +413,7 @@ func lenValidator(match []string, value *generic.Value) error {

func nameValidator(match []string, value *generic.Value) error {
var v = value.String()
if !regexp.MustCompile(`^[a-zA-Z]+(?:[\s-][a-zA-Z]+)*$`).MatchString(v) {
if !regexp.MustCompile(`^[\p{L} .'\-]+$`).MatchString(v) {
return fmt.Errorf("is not valid name")
}

Expand Down

0 comments on commit cf3fb85

Please sign in to comment.