我如何验证某人从出生之日起已超过18岁? [英] How can I validate that someone is over 18 from their date of birth?

查看:79
本文介绍了我如何验证某人从出生之日起已超过18岁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在验证驾驶员的出生日期,从当前日期开始至少应为18.

I am doing validation for Driver's Date of birth, it should be minimum of 18 from the current date.

var Dates = $get('<%=ui_txtDOB.ClientID %>');   
var Split = Dates.value.split("/");

if (parseInt(Split[2]) > 1993) 
{
    alert("DOB year should be less than 1993");
    Dates.focus();
    return false;
}  

我正在使用上面的JavaScript验证来检查一个人的18岁以上的DOB,但这是不正确的.我需要检查今天的日期,并且应该在18岁以上.如何比较和检查当前日期?

I am using this above JavaScript validation for checking a person's DOB above 18, but it is not correct. I need to check with today's date and it should be above 18. How can I compare and check with the current date?

推荐答案

我认为更好的选择是计算用户年龄,并在if语句中使用该年龄.

I think a better alternative would be to calculate the age of the user, and use that in your if statement.

有关此操作的信息,请参见以下SO答案:

See this SO answer on how to do just that:

使用JavaScript计算年龄

这篇关于我如何验证某人从出生之日起已超过18岁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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