RegularExpression Validator doesn't display error message.
Posted
by Rudi Ramey
on Stack Overflow
See other posts from Stack Overflow
or by Rudi Ramey
Published on 2010-03-17T22:17:36Z
Indexed on
2010/03/17
22:21 UTC
Read the original article
Hit count: 440
I have a regular expression validation control initialized to validate a textbox control. I want users to be able to enter U.S. Currency values ($12,115.85 or 1500.22 etc.). I found a regular expression off of regexlib website that does the trick. The validation control seems to be working except for one crucial thing. If invalid data is entered, the validation text dispalys (a red "*" next to the textbox), but the page will still submit and the error message won't pop up... I thought that the error message is supposed to display and the page won't submit if the validation control detects invalid data. Isn't this automatic with ASP .NET? I have searched extensively on how to create validation controls, but haven't found anything different than what I am already doing. Can anyone tell me what I am doing wrong here?
<asp:TextBox ID="txtActualCost" runat="server" Width="120px" CausesValidation="true"></asp:TextBox>
<asp:RegularExpressionValidator ID="regExValActualCost"
ControlToValidate="txtActualCost"
Text="*"
ValidationExpression="^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$"
ErrorMessage="Please enter a valid currency value for 'Actual Cost'"
Display="Dynamic"
EnableClientScript="true"
runat="server" />
© Stack Overflow or respective owner