- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,我正在制作一个接受姓名、年龄和身份证号码的表单。
IC 号码的格式为 yymmdd-xx-xxxx,其中前四个数字是出生日期。的人。最后四个数字是身份证的唯一代码,中间的两个数字是该人出生地的州代码。我想要做的是取身份证号码的前两个数字(出生年份) ),然后减去当前年份,并将其与该人给出的年龄进行比较,输出会表明该年龄是正确还是不正确。
这是我到目前为止所尝试过的。
function valForm() {
function valName() {
var regexName = /^[a-zA-Z]*$/;
if (regexName.test(document.ageVal.name.value)) {
return true;
} else {
return false;
}
}
function valIc() {
var regexIc = /^\d{6}-\d{2}-\d{4}$/;
if (regexIc.test(document.ageVal.icNum.value)) {
return true;
} else {
return false;
}
}
if (!valName()) {
alert("Enter a name using only alphabets");
document.ageVal.name.focus();
document.getElementById("notifName").innerHTML = "Alphabets only";
}
if (!valIc()) {
alert("Correct format is xxxxxx-xx-xxxx");
document.ageVal.icNum.focus();
document.getElementById("notifIc").innerHTML = "Not the correct format";
}
var today = new Date();
var year = today.getFullYear();
var yr = document.getElementById("icNum");
var yrIc = parseInt(yr, 10);
while (yrIc >= 100)
yrIc = Math.floor(yrIc / 10);
fullyrIc = 1900 + yrIc;
var actAge = year - fullyrIc;
var givnAge = document.getElementById("age");
if (actAge == givnAge)
document.getElementById("output").innerHTML = "Age is correct";
else
document.getElementById("output").innerHTML = "Age is not correct";
}
<form name="ageVal" action="javascript:valForm()">
<table border="solid" width="25%">
<tr>
<td>Name: </td>
<td colspan=2>
<input type="text" name="name" id="age">
<div id="notifName"></div>
</td>
</tr>
<tr>
<td>Age: </td>
<td colspan=2>
<input type="number" name="age" id="age">
<div id="notifAge"></div>
</td>
</tr>
<tr>
<td>IC: </td>
<td colspan=2>
<input type="text" name="icNum" id="icNum">
<div id="notifIc"></div>
</td>
</tr>
<tr>
<td colspan=3 align="center">
<input type="text" name="output" id="output" disabled>
</td>
</tr>
</table>
<input type="submit" form="ageVal" value="Submit">
</form>
经过多次尝试并进行大量更改后,我无法获得任何输出。我对 JS 还很陌生,甚至对正则表达式也很陌生,所以我确信我在这里做错了很多事情。
经过一些更改,由于前两个答案,我终于可以得到输出,但现在的问题是计算不正确。我该如何纠正?
最佳答案
output
id 元素是input
元素。使用 value
属性设置值而不是innerHTML来查看任何输出:
if (actAge == givnAge)
document.getElementById("output").value = "Age is correct";
else
document.getElementById("output").value = "Age is not correct";
关于javascript - 验证表单中的年龄但没有得到输出,不确定什么是不正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35969437/
我正在从事一个项目,该项目要求我实现一种方法来确定工作日后一天的人的年龄;也就是每年九月的第一个星期一。 这个方法在以后的年份会用到,所以需要判断当前年份和劳动节后一天的人的年龄。 下面是我用来获取学
我已经在 Play 商店中部署了一个应用程序。我需要获取下载该应用程序的人的年龄 和性别。是否可以获取这些属性,或者我是否需要实现 Google Analytics 才能获取这些属性? 最佳答案 恐怕
我正在尝试根据出生日期计算年龄,我使用 this thread 成功地做到了这一点.但是,我的一些 DateOfBirth 具有空值,并且使用我下面的公式,结果返回为“2012”而不是(空白/空)。
我正在尝试根据财政年度结束时获取年龄。如果我的出生日期是 1962 年 1 月 16 日,那么我当前的年龄是 50 岁(假设今天的日期是 2012 年 1 月 16 日)。我可以使用什么 JavaSc
创建具有以下规范的函数: 函数名称:employee_matcher 目的:将员工姓名与提供的公司、年龄和性别相匹配 参数:公司(字符串)、年龄(整数)、性别(字符串) 返回:员工的名字和姓氏,如下所
1、根据身份证号码计算出生日期、年龄、性别(18位) 复制代码 代码如下: //获取输入身份证号码 var UUserCard = $("#UUserCard").val
适用于OA项目中这些对档案的管理 1、根据身份证号码计算出生日期、年龄、性别(18位) 复制代码代码如下: //获取输入身份证号码 var UUserCa
我将导入表中的数据INSERT INTO插入到我创建的新表中,该表包含有关人员、姓名、地址、出生日期、年龄、性别等的一般信息。 当我插入新表时,导入数据没有年龄,因此我在INSERT INTO之后执行
我如何使用 go standard 构建它? sql包让其他人可以阅读吗?我需要添加很多字段。 result, err := db.Exec( "INSERT INTO MyTable (na
是否有任何简单的 Android/Java 库/框架可以检测图片上的人脸并给我一些关于图片上的人的信息?我的意思是诸如性别、年龄、情绪(微笑、悲伤、愤怒)之类的信息...... 我试过Face++和微
我正在为我的 Android 应用程序使用 Firebase 身份验证。用户可以通过多个提供商(Google、Facebook、Twitter)登录。 成功登录后,有没有办法使用 Firebase a
我想知道是否可以用 PHP 以某种方式检查 session 时限。我浏览了 stackoverflow,但没有找到任何东西。提前感谢您的所有回答。 如果有人想知道为什么我需要知道这样的事情,我想在所有
我正在尝试使用 CakePHP 按出生日期分组并根据结果进行计数。这是我的查询。 $data = $this->User->find('all', array( 'fields' => arr
我正在尝试找出一种使用 Python 3.6 和 Boto 3 通过 aws lambda 函数让用户访问 key 年龄的方法。我的问题是我似乎无法找到正确的 api 调用(如果存在的话)以此目的。我
使用 Seaside 应用程序启动我的图像时,我在启动方法中有此代码: WAMySeasideApp>>startUp: resuming WAMySeasideApp waAppli
谷歌从哪里获得这些数据,是否有可能在没有它的情况下在我自己的网站上手动获得这些数据(假设它以某种Cookie /用户代理字符串/标识符/等形式存在)? 最佳答案 Google从第3方双击Cookie获
我在 Google App Engine 上部署了一个 Django 应用程序,该应用程序过早地将其用户注销。但是没有关闭浏览器窗口/选项卡。在 settings.py 中,我有以下代码: SESSI
我正在通过 Python 使用 YouTube API。我已经可以收集特定视频的所有评论,包括作者姓名、日期和评论内容。 我还可以使用单独的代码提取特定作者的个人信息(年龄、性别、兴趣……)。但我不能
print("how old are you") age = input(">") if age >= 24: print("you are getting old") print (age) els
我是一名优秀的程序员,十分优秀!