You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
410 B
Go
18 lines
410 B
Go
package validation
|
|
|
|
import (
|
|
val "github.com/go-playground/validator/v10"
|
|
"regexp"
|
|
)
|
|
|
|
func safetyText(fl val.FieldLevel) bool {
|
|
asciiPattern := `^[a-zA-Z0-9-_. ]*$`
|
|
unicodePattern := `^[\p{L}\p{N}-_. ]*$`
|
|
|
|
asciiRegex := regexp.MustCompile(asciiPattern)
|
|
unicodeRegex := regexp.MustCompile(unicodePattern)
|
|
|
|
str := fl.Field().String()
|
|
return asciiRegex.MatchString(str) || unicodeRegex.MatchString(str)
|
|
}
|