Personal Git forge.

Code git clone ssh://git.poy.ooo:6969/~poyo/farga ZIP
lib/validation.go / 691B #5a650c83
Raw
package libimport "regexp"var HandleRegex = regexp.MustCompile("^[a-z0-9]+([-_][a-z0-9_]+)*$")const HandleMinLength = 3const HandleMaxLength = 30const UsernameMinLength = 2 const UsernameMaxLength = 40// validates a handle.func ValidateHandle(s string) bool {	// check if the format is correct using the regex	if !HandleRegex.MatchString(s) {		return false	}	// length constraint?	length := len(s)	if length < HandleMinLength || length > HandleMaxLength {		return false	}	return true}// validates a username.func ValidateUsername(s string) bool {	length := len(s)	if length < UsernameMinLength || length > UsernameMaxLength {		return false	}	return true}