mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
17 lines
410 B
Go
17 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)
|
|
}
|