Skip to content

Commit

Permalink
Fixed issue #7976: Date question: keyboard entries not validated
Browse files Browse the repository at this point in the history
Dev: when using the keyboard on the datepicker,
Dev: in the date/time question, invalid dates could be entered
Dev: and submitted. Added validation for dates.
  • Loading branch information
mfaber committed Oct 5, 2013
1 parent d520709 commit 5f1fd13
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions scripts/date.js
Expand Up @@ -17,8 +17,28 @@ $(document).ready(function(){
minDate:new Date(range[0],0,1),
maxDate: new Date(range[1],11,31),
firstDay: "1",
duration: 'fast'
}, $.datepicker.regional[language]);
duration: 'fast',
// Validate input. Necessary because datepicker also allows keyboard entry.
onClose: function() {
format=$('#dateformat'+basename).val();
answer=$('#answer'+basename).val();
//only validate if the format mask says it's a complete date and only a date
var str_regexp = /^[mydMYD]{1,4}[-.\s\/][mydMYD]{1,4}[-.\/\s][mydMYD]{1,4}$/;
var pattern = new RegExp(str_regexp);
if (format.match(pattern)!=null)
{
try
{
newvalue=jQuery.datepicker.parseDate(format, answer);
}
catch(error)
{
alert('Date entered is invalid!');
$('#answer'+basename).val("");
}
}
},
}, $.datepicker.regional[language]);
});

// dropdown dates
Expand Down

0 comments on commit 5f1fd13

Please sign in to comment.