dutch date check

bpluijms 01 Mar, 2009

I am new here and have already searched the forum, but didn't found an answer for my problem.

I am using a form with a date field cf_date (the calendar popup) and I wanna check/validate the following:

[list]- The date has to be in format DD-MM-YYYY.
- The year may not be this year (in this case 2009), but has to be this year - 2 (so in this case 2007, but in 2010 is has to be 2008 and so on).
When I am using validate-date it checks the format DD/MM/YYYY so this is not the right format.
I have tried to set up a server-side validation, but I really don't get it to work.
I am using Mootools to validate the form.

Someone overhere who could help me out?

Thanks a lot!
GreyHead 01 Mar, 2009
Hi bpluijms,


You can add a custom validation with a bit of extra JavaScript. Here's an example that meets your needs (more or less). It's a modified version of the standard date validation. I fyou paste all this into the Form HTML box of a new form and set Validation to On in the Validation tab it shoudl work OK
$script = "
window.addEvent('domready', function() {
  Validation.add('validate-date-dd-mm-yyyy', 'The date must be dd-mm-yyyy', function(v, elm) {
    if(Validation.get('IsEmpty').test(v)) return true;
    var regex = /^(\d{2})\-(\d{2})\-(\d{4})$/;
    if(!regex.test(v)) return false;
    var d = new Date(v.replace(regex, '$2/$1/$3'));
    var d_year = d.getFullYear();
    var year = new Date().getFullYear() - 2;
    var ret = ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) && 
      (parseInt(RegExp.$1, 10) == d.getDate()) && 
      (parseInt(RegExp.$3, 10) == d.getFullYear() &&
      d.getFullYear() == year );
     return ret; 
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( $script );
<input name='date' id='date' class='validate-date-dd-mm-yyyy' type='text' />
<br />
<input type='submit' name='submit' />
NB This line var year = new Date().getFullYear() - 2; sets the required year to this year -2

This topic is locked and no more replies can be posted.