validator

package
v2.3.184 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeviceID validator.Func = func(fl validator.FieldLevel) bool {
	field := fl.Field()
	kind := field.Kind()

	if kind == reflect.Int || kind == reflect.Int64 {
		deviceID := field.Int()
		return model.DeviceIDToName(int(deviceID)) != ""
	} else {
		panic(fmt.Sprintf("Bad type for %s", fl.FieldName()))
	}
}
View Source
var DotUnderscoreHyphen validator.Func = func(fl validator.FieldLevel) bool {
	field := fl.Field()
	kind := field.Kind()

	if kind == reflect.String {
		s := field.String()

		isValid := regexp.MustCompile(`^[a-zA-Z0-9а-яА-ЯёЁ_.-]*$`).MatchString

		return isValid(s)
	} else {
		panic(fmt.Sprintf("Bad type for %s", fl.FieldName()))
	}
}
View Source
var DotUnderscoreHyphenSpace validator.Func = func(fl validator.FieldLevel) bool {
	field := fl.Field()
	kind := field.Kind()

	if kind == reflect.String {
		s := field.String()

		isValid := regexp.MustCompile(`^[\sa-zA-Z0-9а-яА-ЯёЁ_.-]*$`).MatchString
		noSpaces := !strings.HasPrefix(s, " ") && !strings.HasSuffix(s, " ")

		return isValid(s) && noSpaces
	} else {
		panic(fmt.Sprintf("Bad type for %s", fl.FieldName()))
	}
}
View Source
var PhoneNumber validator.Func = func(fl validator.FieldLevel) bool {
	field := fl.Field()
	kind := field.Kind()

	if kind == reflect.String {
		s := field.String()

		if len(s) == 0 {
			return true
		}

		isValid := regexp.MustCompile(`^[\s0-9+*()-]*$`).MatchString
		noSpaces := !strings.HasPrefix(s, " ") && !strings.HasSuffix(s, " ")

		return isValid(s) && noSpaces
	} else {
		panic(fmt.Sprintf("Bad type for %s", fl.FieldName()))
	}
}
View Source
var SpecChars validator.Func = func(fl validator.FieldLevel) bool {
	field := fl.Field()
	kind := field.Kind()

	if kind == reflect.String {
		s := field.String()

		isValid := regexp.MustCompile("^[\\sa-zA-Z0-9а-яА-ЯёЁ`~!@#$%^&*()_+={}\\[\\]\\\\|:;\"/'<>,.?-]*$").MatchString
		noSpaces := !strings.HasPrefix(s, " ") && !strings.HasSuffix(s, " ")

		return isValid(s) && noSpaces
	} else {
		panic(fmt.Sprintf("Bad type for %s", fl.FieldName()))
	}
}

Functions

func DeviceIDValidation added in v2.3.96

func DeviceIDValidation(v *validator.Validate)

func DotUnderscoreHyphenSpaceValidation added in v2.3.96

func DotUnderscoreHyphenSpaceValidation(v *validator.Validate)

func DotUnderscoreHyphenValidation added in v2.3.96

func DotUnderscoreHyphenValidation(v *validator.Validate)

func PhoneNumberValidation added in v2.3.161

func PhoneNumberValidation(v *validator.Validate)

func SpecCharsValidation added in v2.3.96

func SpecCharsValidation(v *validator.Validate)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL