jquery validation for dob to specific format ie dd-mm-yy

$.validator.addMethod("dateFormat",
    function(value, element) {
        return value.match(/^dd?-dd?-dd$/);
    },
    "Please enter a date in the format dd-mm-yyyy.");
And then on your form add:
$('#myForm')
    .validate({
        rules : {
            myDate : {
                dateFormat: true
            }
        }
    });
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

  • wilson

    nice

  • Vins

    Crap, who’ll check its a valid date?
    This will take 99-99-2014 as well

  • davethedev

    not working for me :( I get the validation error message but typing in a correctly formatted date doesn’t fix it

Ending Soon
Free SitePoint Premium

Get one free year of unlimited book and course downloads on SitePoint Premium!