jQuery - how to validate a date of birth using jQuery Validation plugin?

 ̄綄美尐妖づ 提交于 2020-01-15 05:18:31

问题


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"


回答1:


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


来源:https://stackoverflow.com/questions/10982386/jquery-how-to-validate-a-date-of-birth-using-jquery-validation-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!