Hi Folks,

Wondered if anyone could help on this, I've been stuck on it for quite
some time.

I'm trying to validate a date field using a UK date,  here's my code:

 $(document).ready(function(){
    $('#arrival-arrival-date').datepicker({ minDate: new Date
(),defaultDate: +1,dateFormat: 'dd/mm/yy',constrainInput: false });

                                $.validator.addMethod('ukdate', function(value, 
element) {

                                  var regex = 
/^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/]
((19|20)\d\d)$/;
                                                console.log(value.match(regex));
      return this.optional(element) || value.match(regex);
      }, "Please specify a UK date");

                                 // validate signup form on keyup and submit
    $("#theForm").validate({
                                    debug:true,
                                                                errorClass: 
'redBorder',
                                                                rules: {
            'arrival-arrival-date': {
                ukdate: true},
            'arrival-stay-duration': {
                required: true,
                min: 1}
          },
                                                                                
highlight: function(element, errorClass) {
            $(element).fadeOut(function() {
              $(element).fadeIn()
                                                                                
                                })
          },
                                                                                
messages: {
                                                                                
 'arrival-arrival-date':'',
                                                                                
        'arrival-stay-duration':''
                                                                                
},
                                                                         
highlight: function(element, errorClass) {
                                                                                
                $(element).addClass(errorClass);
                                                                                
},
                                                                                
unhighlight: function(element, errorClass) {
                                                                                
                $(element).removeClass(errorClass);
                                                                                
},
                                                                                
errorPlacement: function(error, element) {
            error.appendTo('errorNotes');
          }
    });



And you can see a demo of it in action at
http://dev.letsbookrooms.co.uk/uk/perthshire/parklandshotel/.  It
works fine on IE, Opera and FF, fails in Safari for any dates where
the dd part is higher than 12.

I think it must be an issue with the validator plugin as I've tested
the regular expression on its own in Saari and it works fine.

Cheers

George

Reply via email to