How to enforce Maximum character length Validation or how to allow maximum of 5 letters?

 Posted by vishalneeraj-24503 on 7/8/2014 | Category: ASP.NET Interview questions | Views: 1575 | Points: 40

We will use RegularExpressionValidator control to achieve this task:-

Refer below code:-
<asp:TextBox Id = "txt_employee_code" runat = "server"></asp:TextBox>

<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "txt_employee_code" Id = "reg_ex_employee_code" ValidationExpression = "^[\s\S]{0,5}$" runat = "server" ErrorMessage = "Maximum of 5 letters allowed"></asp:RegularExpressionValidator>

It will allow only 5 letters after that it will give error mmessage as Maximum of 5 letters allowed

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response