Set minimum number of characters in Textbox

0

How can I set a minimum amount of characters that should be set to a textbox ?

I'm using Visual Studio 2013, creating a site in aspx.

    
asked by anonymous 29.07.2016 / 21:13

3 answers

1

It's very simple, if you're using asp:TextBox just use a asp:RegularExpressionValidator , getting as follows

<asp:TextBox runat="server" ID="TextBox1" MaxLength="100"></asp:TextBox>
<asp:RegularExpressionValidator ID="valPassword"
        runat="server"
        ControlToValidate="TextBox1"
        ErrorMessage="Tamanho mínimo pro TextBox é 5"
        ValidationExpression=".{5}.*" />
    
30.07.2016 / 15:58
0

Just make a filter by checking the number of characters in the TextBox.

if(textBox1.TextLenght > 5) //Ou qualquer outro número que você definir
{
    FacaOQueTemQueFazer();
}
    
29.07.2016 / 21:29
0

Add a very basic check in the event where you will validate what is in the TextBox.

Let's take a look at% of your TextBox, and% of it's limit (obviously), and consider this method a button, or whatever you want to do with it.

void Validando(Object sender, EventArgs args) {
    if (TextBox1.Length >= limite) {
         // OK, passou do limite mínimo
    } else {
         // não passou
    }
}

Or, to use in a simpler way:

if (!TextBox1.Length >= limite) return;
    
30.07.2016 / 06:33