gpt4 book ai didi

JavaScript 18 岁以下出生日期

转载 作者:行者123 更新时间:2023-12-01 02:30:52 24 4
gpt4 key购买 nike

有没有办法对完整的出生日期(日/月/年)进行验证,以确定用户是否未满 18 岁。我发现的大多数教程仅向我展示用户年龄(不是出生日期)低于 18 岁时如何操作。顺便说一句,我还在我的出生日期文本框中使用“日期”输入类型。HTML

<body>
<header class="v-header container">
<div class="fullscreen-backgorund-Booking">
</div>
<div>
<ul>
<li><a href="Home">Home</a></li>
<li><a href="McLaren Vale">McLaren Vale</a></li>
<li><a href="Barossa">Barossa</a></li>
<li><a href="Clare">Clare</a></li>
<li><a href="Online Booking">Online Booking</a></li>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<a href="Home">Home</a>
<a href="McLaren Vale">McLaren</a>
<a href="Barossa">Barossa</a>
<a href="Clare">Clare</a>
<a href="Online Booking">Online Booking</a>
</div>
<span id="sidebtn" onclick="openNav()">&#9776;</span>
</ul>
</div>

<div class="header-overlay"></div>
<div class="header-content" style="width: 100%;">
<!-- width... is not working in external css... why?-->

<h1 style="margin-top: -100px;">Online Booking</h1>
<form name="myForm" action="/action_page.php" onsubmit="return validateForm()" method="post">
<input type="text" name="fname" placeholder="Firstname"> Date of Brith
<input type="date" name="DoB" placeholder="Date of Birth">
<input type="text" name="TelNumber" placeholder="Telephone number">
<input type="email" name="email" placeholder="Email"> Date of Tour
<input type="date" name="DoT" placeholder="Date of tour (dd.mm.yyyy)">
<form action="" id="calculate" onsubmit="return false;">

<input type="text" placeholder="Number of Travellers" id="val" name="val" value="" />
<label class="radiolabel">
<input type="radio" name="button" value="100">McLaren</label>
<label class="radiolabel">
<input type="radio" name="button" value="150">Barossa</label>
<label class="radiolabel">
<input type="radio" name="button" value="90">Clare</label>
<div id="result" style="display: block;">
Result:</div>
<input type="submit" id="submit" value="Submit" onclick="endresult(document.forms['myForm'].elements['button']);">
</div>

</form>
</div>

最佳答案

我会首先计算年龄,然后检查他是否超过 18 岁。这是代码片段。

var birthday1 = new Date("2015-03-25");
var birthday2 = new Date("1994-03-25");

function isOverEighteen(birthday) {
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs);
var age = Math.abs(ageDate.getUTCFullYear() - 1970);
if(age > 17){
return true;
}else{
return false;
}
}

console.log(isOverEighteen(birthday1));
console.log(isOverEighteen(birthday2));

关于JavaScript 18 岁以下出生日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48318305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com