Limit the number of characters in a textbox

Asked

Viewed 29 times

-1

Hello, I am trying to "create" a system of "captcha" for my program, but it sometimes exceeds the limit of the textbox, and in this case the user would not know what comes next, I researched a lot, but I have not found a solution, I will be leaving a little of the code below, and I thank you in advance for your help.

Random random = new Random();
tb_noRobot.MaxLength = 1;
tb_noRobot.Text = Criptography.GerarHashMd5(random.Next().ToString());

Note: "criptography" is the default method of generating the hash of values.

  • I couldn’t understand what you intended... nor the sense of generating a guid to display only the first character

1 answer

1


If your method returns a String you can delete the characters following the amount you want, for example limit to 5 characters:

Random random = new Random();
tb_noRobot.MaxLength = 1;
tb_noRobot.Text = Criptography.GerarHashMd5(random.Next().ToString()).Substring(0,5); //retorna os 5 primeiros caracteres, só alterar o '5' para a qtd necessária.
  • 1

    Thank you very much for the help, probably this will help a lot, I’m still new in the area, I didn’t know it was possible something like this...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.