Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload