promptui icon indicating copy to clipboard operation
promptui copied to clipboard

Prompt Validation: regex matching causes multiple rerenders on input

Open jenil777007 opened this issue 2 years ago • 3 comments

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

jenil777007 avatar Jun 24 '22 09:06 jenil777007

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.

sabino-ramirez avatar Aug 27 '22 23:08 sabino-ramirez

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

banfg56 avatar May 24 '23 13:05 banfg56

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
  },
}

smnspz avatar Oct 05 '23 16:10 smnspz