yrazlik
yrazlik

Reputation: 10777

What is wrong with this validator in asp.net?

I am trying to put a validator in my page that checks the value of a textbox and prints the error message if the value of the textbox is not a number of length 3. Here it is:

 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
        ControlToValidate="tCourse" ErrorMessage="Enter a number of length 3!" 
        ForeColor="Red" ValidationExpression="^[0-9]]{3}$"></asp:RegularExpressionValidator>

The problem is, even though i enter a number like "432" into the box, it still gives the error message. What is wrong here can anyone see?

Thanks

Upvotes: 2

Views: 65

Answers (3)

Dennis Rongo
Dennis Rongo

Reputation: 4611

Try this:

ValidationExpression="\d{3}"

Upvotes: 1

Dan McClain
Dan McClain

Reputation: 11920

You have ^[0-9]]{3}$ there is a double closing ], try ^[0-9]{3}$

Upvotes: 1

Michael La Voie
Michael La Voie

Reputation: 27926

Your RegEx has an extra "]" in it:

^[0-9]]{3}$

Should be:

^[0-9]{3}$

If you're curious, your current regex should match "4]]]" as a valid entry

Upvotes: 2

Related Questions