You need to use RegularExpressionValidator
Ref:
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator Display="Dynamic" ControlToValidate="TextBox3" ID="RegularExpressionValidator3"
ForeColor="Red" ValidationExpression="^[\s\S]{5,8}$" runat="server" ErrorMessage="Minimum 5 and Maximum 8 characters required."></asp:RegularExpressionValidator>