0

Html (Full Code)

<asp:TextBox ID="txtSasiNo" runat="server" Width="250px" MaxLength="17"></asp:TextBox>
<asp:RegularExpressionValidator CssClass="zorunlu" ValidationGroup="kaskoTeklifSayfasi" Display="Dynamic" ID="rangevalidator1" runat="server" SetFocusOnError="true" ControlToValidate="txtSasiNo" ErrorMessage="Enter number characters only (8 or 17)" ValidationExpression="^\d{8}$|^\d{17}$""></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="rfvSasiNo" SetFocusOnError="true" ValidationGroup="kaskoTeklifSayfasi" runat="server" Display="Dynamic" ControlToValidate="txtSasiNo" CssClass="zorunlu">Please enter Number.</asp:RequiredFieldValidator>

Question:

I am trying to use RangeValidator.

If txtnumber is null or empty and if txtnumber is not 8 characters or not 17 characters. Only 2 options first option is 8 character second option is 17 character.

txtnumber text character only can be like below

12345678    // This is 8 characters
12345678901234567    // This is 17 characters

What to add to RangeValidator in order to achieve this ?

Thanks.

3 Answers 3

1

As described by Ondrej you can use RegularExpressionValidator. To be more specific with the aspx. See the code below:-

UPDATED CODE:

Here you go:-

<asp:TextBox ID="txtnumber" runat="server" Width="250px"></asp:TextBox>
<asp:RegularExpressionValidator Display="Dynamic" ID="regtxt" runat="server" SetFocusOnError="true" ControlToValidate="txtnumber" ErrorMessage="Enter number characters only (8 or 17)" 
    ValidationExpression="^\d{8}$|^\d{17}$"></asp:RegularExpressionValidator>

Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

1

Don't use range validator - use regex validator instead:

<asp:RegularExpressionValidator ValidationExpression="^([0-9]{8})|([0-9]{17})$" ... />

1 Comment

Hello thanks for answer however it is not working for 17 any idea please ?
0

The validators usually ignore empty fields. Notable exception: the RequiredFieldValidator. Add that to guard against empty fields and keep the RangeValidator to force a specific range of values.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.