-
Notifications
You must be signed in to change notification settings - Fork 6
Add MinLen validator #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MinLen validator #164
Conversation
ui/options.go
Outdated
func WithValidateMinLen(length int) Option { | ||
return WithValidateFunc(MinLen(length)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use WithValidateMinLength
and MinLength
instead of MinLen
. If we want to shorten it, we can name it WithMinLength
.
ui/validators.go
Outdated
|
||
// MinLen is a validation function that checks for a minimum length. | ||
// An input length <= 0 indicates that the check should not be performed. | ||
func MinLen(length int) promptui.ValidateFunc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
ui/validators.go
Outdated
re := regexp.MustCompile(`\s+`) | ||
next := re.ReplaceAllString(s, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please no, you can use strings.TrimSpace(s)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or perhaps just strings.TrimRightFunc(s, unicode.IsSpace)
as we use in other places.
- MinLen -> MinLength - regex -> strings.TrimSpace
No description provided.