Date validations

ultraman

Well-known member
Joined
Dec 31, 1969
Messages
138
Location
Quebec, Canada
Hi ! Im using a CompareValidator to make sure that the text entered in a TextBox is a valid date.

Heres my simple code (In Page_Load) :

[VB]
cvDateDebut.ControlToValidate = "txtDateDebut"
cvDateDebut.Type = ValidationDataType.Date
cvDateDebut.Operator = ValidationCompareOperator.DataTypeCheck
cvDateDebut.ErrorMessage = "Not a valid date"
[/VB]

It works fine, but Id like it to be valid when theres "N/A" in the TextBox. Is there a way to do it other than with JavaScript ?
 
You could try putting that whole piece of code inside an if/then statement:

If textbox.text <> "NA" Then
Your code block here
Else
Whatever you were gonna do with the NA
End If

Hope that helps.

Eva
 
I am not sure why you think if the user changes the value there would be no validation. Either the value is exactly NA or it isnt. If it isnt then validate it.

If the user changes the value it should go through the if..then process again and be checked again.
 
Back
Top