Skip to content
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

Prompt Validation: regex matching causes multiple rerenders on input #207

Open
jenil777007 opened this issue Jun 24, 2022 · 3 comments
Open

Comments

@jenil777007
Copy link

jenil777007 commented Jun 24, 2022

Issue reproduction:

emailPrompt := promptui.Prompt{
  Label: "Email",
  Validate: func(input string) error {
	  match, err := regexp.MatchString("([a-z]+)@email.com", input)
	  if err != nil {
		  log.Fatal(err)
		  os.Exit(1)
	  }

          if !match {
		return errors.New("Please provide a valid email. i.e. [email protected]")
	}
  },
}

Issue:

Screenshot 2022-06-24 at 2 41 24 PM

@sabino-ramirez
Copy link

hi @jenil777007 did you find a solution to this issue? Something similar happens when the input exceeds the length of the terminal and starts a new line.

@banfg56
Copy link

banfg56 commented May 24, 2023

config Templates in promptui.Prompt to control output content format,more detail please refer template

@smnspz
Copy link

smnspz commented Oct 5, 2023

Try this:

emailPrompt := promptui.Prompt{
  Label: "Email",
  Validate: func(input string) error {
          regex := regex.MustCompile(`([a-z]+)@email.com`)
          if !regex.MatchString(input) {
                  return errors.New("Wrong mail format")
          }
          return nil
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants