Type InputOTPFilter

type InputOTPFilter uint8

InputOTPFilter selects which characters a one-time code accepts, after the input-otp package's patterns: REGEXP_ONLY_DIGITS and REGEXP_ONLY_DIGITS_AND_CHARS. The zero value accepts any visible character.

Constants

const (
	// InputOTPAny accepts every character except whitespace and controls.
	InputOTPAny InputOTPFilter = iota
	// InputOTPDigits accepts the ASCII digits 0-9.
	InputOTPDigits
	// InputOTPAlphanumeric accepts the ASCII digits and letters.
	InputOTPAlphanumeric
)

Methods

Accepts#

func (filter InputOTPFilter) Accepts(r rune) bool

Accepts reports whether the filter lets r into the code.

Normalize#

func (filter InputOTPFilter) Normalize(text string, slots int) string

Normalize is what a caller-owned editor should store after text is typed or pasted: text reduced to the characters the filter accepts and cut to slots characters (6 when slots is not positive), so a pasted "123-456" becomes "123456" for a digit code. Text that needs no change is returned as is, without allocating.