I'm trying to validate a TextBox used for the username in the user registration page. The conditions are:
I'm using a RegularExpressionValidator to check both conditions at the same time but this results in the same error message: "Username should be maximum 8 characters long and start with an uppercase letter."
.
I would like to display specific error messages based on the above conditions, say:
I want both error messages to appear if both conditions are not satisfied.
Here is my present code:
<asp:TextBox ID="username" runat="server" CssClass="InputText"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvUsername" runat="server"
ControlToValidate="username" Display="Dynamic"
EnableClientScript="true">Username is required
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="revUsername" runat="server" Display="Dynamic"
ControlToValidate="username"
ValidationExpression="[A-Z][A-Z0-9]{0,7}" >
Username should be max 8 characters long
and should start with an alphabet.
</asp:RegularExpressionValidator>
How do I achieve this?
<asp:TextBox ID="username" runat="server" MaxLength="8" CssClass="InputText"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvUsername" runat="server"
ControlToValidate="username" Display="Dynamic"
EnableClientScript="true">Username is required
</asp:RequiredFieldValidator>
for first letter uppercase Regex to check if the first character is uppercase