Solved

RegularExpressionValidator ErrorMessage not cleared.

Posted on 2008-06-17
9
1,300 Views
Last Modified: 2010-09-14
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
Comment
Question by:sandya_116
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 21804364
>>>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
 

Author Comment

by:sandya_116
ID: 21804495
The cursor is leaving the textbox. I am in another control. But still the error message doesn't clear up.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21804758
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
 

Author Comment

by:sandya_116
ID: 21805158
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 22

Expert Comment

by:prairiedog
ID: 21805663
>>>if select an existing number.
How do you select a number for the textbox? Are you talking about the history data?
0
 

Author Comment

by:sandya_116
ID: 21805837
Yes I am talking about the history data.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21805907
That might be the problem.
0
 

Author Comment

by:sandya_116
ID: 21806422
Is there anything I can do for this problem?
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 21806570
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now