jQuery 将信用卡到期日期验证为未来日期
我似乎无法做到这一点,我可以让它捕获过去的日期,但不能在未来的日期返回 true。我只需要验证我的表单的信用卡到期日期是在未来,这是行不通的,有什么想法吗?日期必须采用 MM/YYYY 格式,中间有“/”。
$.validator.addMethod(
"FutureDate",
function(value, element) {
var startdatevalue = (.getMonth/.getYear);
return Date.parse(startdatevalue) < Date.parse($("#ExpirationDate").val());
},
"End Date should be greater than Start Date."
);
I can't seem to get this right, I can get it to catch a past date, but not return true on future date.I just need to validate my form's Credit Card Expiration Date as being in the future, this isn't working, any ideas? the date has to be in the format MM/YYYY with a "/" in between them.
$.validator.addMethod(
"FutureDate",
function(value, element) {
var startdatevalue = (.getMonth/.getYear);
return Date.parse(startdatevalue) < Date.parse($("#ExpirationDate").val());
},
"End Date should be greater than Start Date."
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你实际上并没有让它赶上过去的约会。如果您将像“11/2010”这样的日期传递给
Date.parse()
,它将返回NaN
(或不是数字),这是逻辑相当于返回false
。尝试这样做看看我的意思:
如果你添加一个日期数字,它应该可以工作。类似于:
当然,这个示例使用硬编码日期。如果值存储为
11/2010
,您可以尝试如下操作:You're not actually getting it to catch a past date. If you're passing a date like this "11/2010" to your
Date.parse()
, it is returningNaN
(or Not a Number) which is the logical equivalent to returningfalse
.Try doing this to see what I mean:
If you add a day number, it should work. Something like:
Of course, this example uses a hard coded date. If the values are stored as
11/2010
, you could try something like this: