3

I want to validate an input ( date of birth ) using jQuery Validation plugin, but it must be in format "dd/mm/yyyy" and also not validate when the date of year is over 2002.

So the date is valid when it's in this format "dd/mm/yyyy" and year over "2002"

Sparky
  • 98,165
  • 25
  • 199
  • 285
kach
  • 799
  • 3
  • 13
  • 23
  • 1
    Where is your code? What have you tried? [Do you expect a complete solution from scratch?](http://meta.stackexchange.com/a/128553) – Sparky Jun 11 '12 at 14:48
  • 1
    http://mattgemmell.com/2008/12/08/what-have-you-tried/ – NDBoost Jun 11 '12 at 14:52

1 Answers1

5

I find the answer :D this is it. Thanks all

$.validator.addMethod("birth", function (value, element) {
        var year = value.split('/');
        if ( value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/) && parseInt(year[2]) <= 2002 )
            return true;
        else
            return false;
    });
kach
  • 799
  • 3
  • 13
  • 23