<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function checktype()
{
year=document.fm.year.value;
email=document.fm.email.value;
age=document.fm.age.value;
if(year.length!=4||isNaN(year))
{
alert("年份不正确!");
return false;
}
if(email.length==""||(email.indexOf('@')==-1)||(email.indexOf('.')==-1))
{
alert("电子邮件输入错误!");
return false;
}
if(age.length!=2||isNaN(age)||parseInt(age)<20||parseInt(age)>50)
{
alert("你的年龄不符合我们的要求");
return false;
}
return true;
}
</script>
</head>
表单验证
最新推荐文章于 2025-12-13 12:07:42 发布
本文介绍了一个简单的HTML表单验证脚本,用于检查用户输入的年份、电子邮件和年龄是否符合特定的标准。具体而言,该脚本确保年份为四位数字、电子邮件地址格式正确且包含@和.符号、年龄为两位数并且介于20到50岁之间。
493

被折叠的 条评论
为什么被折叠?



