Problem with CompareValidator control

A

Andres Aguiar

Hi,

I'm using the CompareValidator with a DateTime field using the dd/MMM/yyyy
format (example "07/Jun/2004" ) .

The compare validator seems not work with this format. It always says that
the date is invalid.

I'm using the CompateValidator with Operator= "DataTypeCheck" and
Type="Date".

<asp:CompareValidator runat="server" id="ValidateDate"
ControlToValidate="InvoiceDate" Operator="DataTypeCheck" Type="Date"
ErrorMessage="invalid date" ></asp:CompareValidator>

What am I missing?

Thanks

Andres
 
S

Steven Cheng[MSFT]

Hi Andres,

As for the Validation Date problem on using the CompareValidator control.
This is because the CompareValidator's support on date validtion only
contain some basic date formats such as:
mm/dd/yyyy or dd/mm/yyyy ... and not all those formats we can cover.
Also, we can't force it to validate regarding on a specified format.
And as for your scenario, I think the CustomValidator or RegularExpression
Validator control maybe suitable. And here is a former thread discussing on
the similiar problem, you may have a look:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=iu91ie8YEHA.3120%
40cpmsftngxa06.phx.gbl&rnum=1&prev=/groups%3Fq%3Dasp.net%2520date%2520valida
tion%2520regex%26hl%3Den%26lr%3D%26ie%3DUTF-8%26sa%3DN%26tab%3Dwg

Also, below are some regex for validting date/time resources which maybe
useful if you'll use the RegularExpressionValidator to check the date input:
#Regex Lib for DAte/Times
http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=5&categoryId=5

#RegEx Short Date Validation
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=474

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top