We help IT Professionals succeed at work.
Get Started

Using the date picker for client side date validation

394 Views
Last Modified: 2012-05-12
My website currently has 3 drop down for date: a Month, a Day and a Year drop downs. It's looking like to simply add client side validation wil be easiest if I use the jQuery UI Date Picker as a background validator.

I need to check date like 2/30/2000 and tell the user it's an invalid date. I have the folowing validation code that's working:

            onClose: function (dateText, inst) {
                if (dateText != $.datepicker.formatDate($.datepicker.regional[''].dateFormat, new Date(dateText))) {
                    alert("The date you specified is not a valid date.");
                    setTimeout(function () { $("DOB").focus(); }, 250);
                }
            }

How can I use this as a background validation test? I'd need to re-write it as a stand-alone JavaScript function, right?

How would I make the click event for the button succeed when the date is valid, yet fail and abort the submission when it's a bad date?

Please explain how I'd show the error message.

Thanks!
Comment
Watch Question
CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE