Link to home
Start Free TrialLog in
Avatar of gilkesy
gilkesy

asked on

Custom validation of date when DropDown Lists are used

I have a form where a client can enter a date using 3 DropDown lists (Day, Month, Year)

I need to create a custome validation to check whether the date is valid. I'm not sure how to do this because custom validation seems to only apply to a single control and not 3 controls as is the case here.

How should I tackle this?
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

You've got a few choices here...
1. Use server-side validation (which you should do anyways, since the validators use javascript, and js may be disabled).
2. Write javascript to populate the day combo based on the month combo (I assume you're trying to eliminate Feb 31, etc). If you take this approach, you probably need to incorporate the year into the mix as well, to allow Feb 29.
3. Write js to perform custom validation. You need to use a CustomValidator control, and set the ClientValidationFunction property to your js validation function name.
Avatar of gilkesy
gilkesy

ASKER

Well I was thinking something along the lines of this:

        If IsDate(dropDOBDD.SelectedValue & "/" & dropDOBMM.SelectedValue & "/" & dropDOBYY.SelectedValue) = False Then
            DOBValidator.Text = "Invalid Date"
            e.IsValid = False
        Else
            e.IsValid = True
            Session("DOB") = CDate(dropDOBDD1.SelectedValue & "/" & dropDOBMM1.SelectedValue & "/" & dropDOBYY1.SelectedValue)
        End If

Right... That looks like option 1 (server-side). The drawback to server-side validation is that it requires a postback. If you write roughly equivalent code in java, then it runs on the client, and the user can't postback invalid data -- plus, they don't have to wait for the error message.

Avatar of gilkesy

ASKER

I'm going to stick with server side validation for now. Perhaps add client side later in the project.
ASKER CERTIFIED SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gilkesy

ASKER

Thanks