jquery validate date of birth format dd-mm-yy

Sam Deering
Tweet

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
            }
        }
    });

Get your free chapter of Level Up Your Web Apps with Go

Get a free chapter of Level Up Your Web Apps with Go, plus updates and exclusive offers from SitePoint.

  • wilson

    nice

  • davethedev

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