limiting the text box to have only a particular limit of numbers and characters

advertisements

I have a text box with label name Employee Id and a text box to provide employee id now to this text box i should set a validation to have a limit up to 5 numbers or characters if the user tries to enter more than 5 characters or numbers it should display an error message your maximum limit is only 5.

Employee ID*

here i have no button to the text box hence while entering only if the limit exceeds 5 it should display the error message before going to next text box.can you please help me out.


Below code will help you. Maximum and Minimum character length validation for 5 character.

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "TextBox1" ID="RegularExpressionValidator1" ValidationExpression = "^[\s\S]{0,5}$" runat="server" ErrorMessage="Your maximum limit is only 5"></asp:RegularExpressionValidator>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "TextBox1" ID="RegularExpressionValidator1" ValidationExpression = "^[\s\S]{5,}$" runat="server" ErrorMessage="Minimum required limit is 5"></asp:RegularExpressionValidator>