护照到期日验证 [英] Passport expiry date validation

查看:82
本文介绍了护照到期日验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Need help for below query...

Form has passport expiry field and validation for field is, passport must have at least 6 months validity from current date.

I have to do it in asp.net... so pls help me for this.





我尝试了什么:



我使用自定义验证器



What I have tried:

I am using custom validator

I have to do it in asp.net... so pls help me for this.

推荐答案

从用户那里读取密码到期日期。将其转换为DateTime值。

使用DateTime.Now获取当前日期。使用AddMonths添加六个月。

比较两个日期。如果有效期最长,那很好。如果不是,它就不会持续足够长的时间。



这是你的作业,所以我不会给你任何代码!除了我?我是用JavaScript做的,而不是强行往返服务器。
Read the password expiry date from the user. Convert it to a DateTime value.
Get the current date using DateTime.Now. Add six months using AddMonths.
Compare the two dates. If the expiry date is the greatest, it's fine. If it isn't, it doesn't last long enough.

This is your homework, so I'll give you no code! But me? I'd do it in JavaScript rather than force a round trip to the server.



.validator.addMethod( expiryValidator,function(value,element){
var val = Date.parse(value);
if(isNaN(val))
return false;

var d = new Date(val);
var f = new Date();

f.setMonth(f.getMonth()+ 6);
if(d < f){
返回false;
}

返回true;
});
.validator.addMethod("expiryValidator", function (value, element) { var val = Date.parse(value); if (isNaN(val)) return false; var d = new Date(val); var f = new Date(); f.setMonth(f.getMonth() + 6); if (d < f) { return false; } return true; });


这篇关于护照到期日验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆