Regular expressions are read to read, can't spot any obvious error
with that, especially considering that it fails only in Safari.

Here is a custom method for italian dates, not using regex, maybe it helps:

jQuery.validator.addMethod(
        "dateITA",
        function(value, element) {
                var check = false;
                var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
                if( re.test(value)){
                        var adata = value.split('/');
                        var gg = parseInt(adata[0],10);
                        var mm = parseInt(adata[1],10);
                        var aaaa = parseInt(adata[2],10);
                        var xdata = new Date(aaaa,mm-1,gg);
                        if ( ( xdata.getFullYear() == aaaa ) && ( 
xdata.getMonth () == mm -
1 ) && ( xdata.getDate() == gg ) )
                                check = true;
                        else
                                check = false;
                } else
                        check = false;
                return this.optional(element) || check;
        },
        "Please enter a correct date"
);

From: http://jquery.bassistance.de/validate/additional-methods.js

Jörn

On Wed, Feb 18, 2009 at 3:25 PM, George <george.bea...@googlemail.com> wrote:
>
> 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