0
How can I define a minimum amount of characters that should be put into a textbox
?
I’m using Visual Studio 2013, creating an aspx site.
0
How can I define a minimum amount of characters that should be put into a textbox
?
I’m using Visual Studio 2013, creating an aspx site.
1
It’s very simple if you’re using the asp:TextBox
just use a asp:RegularExpressionValidator
, being 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}.*" />
0
Only make a filter by checking the amount of characters in the Textbox.
if(textBox1.TextLenght > 5) //Ou qualquer outro número que você definir
{
FacaOQueTemQueFazer();
}
0
Add a very basic check in the event where you will validate what is in the Textbox.
Let’s consider TextBox1
its Textbox, and limite
the 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, use in a simpler way:
if (!TextBox1.Length >= limite) return;
Browser other questions tagged c# asp.net
You are not signed in. Login or sign up in order to post.
You can check the amount of characters in the textbox Textchanged event.
– Daniel Junior
what exactly are you using? Asp-net MVC? which version?
– Eduardo Moreira
You can try using input: <input id="test" runat="server" type="text" Pattern=". {3,}" title="3 characters minimum" /> http://stackoverflow.com/questions/10281962/is-there-a-min-validation-attributin-html5
– Mauricio Ferraz