• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1411
  • Last Modified:

RegularExpressionValidator ErrorMessage not cleared.

I have the following code to validate creditcard using RegularExpressionValidator. When I enter a valid credit card no 1111111111111111, it doesn't show an error message which is good. When I enter an invalid credit card no 11, it does show the error message which is also good. But the problem I have is when I enter back the credit card no 1111111111111111, it doesn't clear the error message. If I delete the credit card no, it clears the error message and when I enter back 1111111111111111, it doesn't show any error message.

<asp:TextBox Columns="35" CssClass="Content" ID="CreditCardNumber" MaxLength="19" Runat="server"/>
<asp:RegularExpressionValidator ID="regExCreditCardNumber" runat="server"
                            ControlToValidate="CreditCardNumber" Display="Dynamic" ValidationExpression="Some Expression" ErrorMessage="Please enter a valid Credit Card Number" />
0
sandya_116
Asked:
sandya_116
  • 5
  • 4
1 Solution
 
prairiedogCommented:
>>>But the problem I have is when I enter back the credit card no 1111111111111111, it doesn't clear the error message.
Remember, thought, you cursor has to leave the textbox in order for the validator to work.
0
 
sandya_116Author Commented:
The cursor is leaving the textbox. I am in another control. But still the error message doesn't clear up.
0
 
prairiedogCommented:
I copied and pasted your code in my web application, and I didn't have any problem to run the application. The error message cleared up as I followed the steps you specified in your question.
I would try to set MaxLength=16 so that I would not mistakenly enter more digits in the textbox. You know, it is hard to tell if there are 16 "1"s or 17 "1"s in the textbox.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sandya_116Author Commented:
Now that I looked at it more, I found that the problem comes only when user selects an already typed in number. I made sure that it was 16 digits. If I retype the number, the error message clears up. I am not sure why the error doesn't clear up, if select an existing number.
0
 
prairiedogCommented:
>>>if select an existing number.
How do you select a number for the textbox? Are you talking about the history data?
0
 
sandya_116Author Commented:
Yes I am talking about the history data.
0
 
prairiedogCommented:
That might be the problem.
0
 
sandya_116Author Commented:
Is there anything I can do for this problem?
0
 
prairiedogCommented:
Are you using .NET 2.0 and Visual Studio 2005? If yes, then there is a property for the textbox called "AutoCompleteType", you can set it to Disabled. It will prevent the textbox from remembering the data previously entered.

If not, then you need to add this line in your code to do the same thing above:
CreditCardNumber.Attributes.Add("autocomplete", "off")
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now