Search Apps Documentation Source Content File Folder Download Copy Actions Download

string_text.gno

0.50 Kb · 22 lines
 1package validate
 2
 3import (
 4	"strings"
 5	"unicode/utf8"
 6)
 7
 8// AssertStringTextLen validates a plain text value against the text hard cap.
 9func AssertStringTextLen(value string, allowEmpty bool, panicMessagePrefix string) {
10	if !allowEmpty && strings.TrimSpace(value) == "" {
11		panic(panicMessagePrefix + " is required")
12	}
13
14	valid, message := StringPlain.Validate(value)
15	if !valid {
16		panic(message)
17	}
18
19	if utf8.RuneCountInString(value) > StringText.Max() {
20		panic(panicMessagePrefix + " exceeds max runes")
21	}
22}