The name of the plugin is jquery.ui.datepicker.validation.js
; dpDate
is one of the new validation methods it defines. For the benefit of other readers, it can be found at:
http://keith-wood.name/uiDatepickerValidation.html
This method simply uses $.datepicker.parseDate
using the dateFormat you specified -- if it doesn't report an error, it considers the input valid. Since parseDate
allows abbreviated years, so does the plugin.
Instead, you can use the regular expression /^\d{4}-\d{2}-\d{2}$/
; this question shows how to add a regex
validation method. If you combine it with the dpDate
method, it will check that it has 4 digits and that it's also a valid date.
jQuery validate: How to add a rule for regular expression validation?
What I do in my application is a little different. I simply don't allow the user to edit the date field directly. I set it readonly
, but this still allows the datepicker to fill it in. Since the datepicker always enters 4-digit years, I don't have to worry much about validating it.