JavaScript學習(1)初識JavaScript
阿新 • • 發佈:2019-02-06
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 日期驗證格式 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<form name ="datecheck" method="POST" onsubmit="return dateCheck(this.date.value);">
<table border="0" cellpadding="8" cellspacing="0" width="50%">
<tr>
<td align="right" nowrap>日期(DD/MM/YYYY):</td>
<td><input type=text name="date" size="25"></td>
</tr>
<tr>
<td class="center" colspan="2">
<input type=submit value="提交">
<input type=reset value="重寫">
</td>
</tr>
</table>
</form>
<script type="text/javascript" language="javascript">
function dateCheck(str)
{
var re = new RegExp("^([0-9]{1,2})[./]{1}([0-9]{1,2})[./]{1}([0-9]{4})$");
var ar;
var res = true;
if(ar=re.exec(str)!=null)
{
var i;
i=parseFloat(ar[1]);
if(i<=0||i<31)document.ADDUser.PWD.focus();
{
res=false;
}
i=parseFloat(ar[2]);
if(i<=0||i>12)
{
res=false;
}
}
else{
res=false;
}
if(!res){
alert('請輸入 DD/MM/YYYY 日期格式');
}
else{
alert("success");
}
return res;
}
</script>
</HEAD>
<HTML>
<HEAD>
<TITLE> 日期驗證格式 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<form name ="datecheck" method="POST" onsubmit="return dateCheck(this.date.value);">
<table border="0" cellpadding="8" cellspacing="0" width="50%">
<tr>
<td align="right" nowrap>日期(DD/MM/YYYY):</td>
<td><input type=text name="date" size="25"></td>
</tr>
<tr>
<td class="center" colspan="2">
<input type=submit value="提交">
<input type=reset value="重寫">
</td>
</tr>
</table>
</form>
<script type="text/javascript" language="javascript">
function dateCheck(str)
{
var re = new RegExp("^([0-9]{1,2})[./]{1}([0-9]{1,2})[./]{1}([0-9]{4})$");
var ar;
var res = true;
if(ar=re.exec(str)!=null)
{
var i;
i=parseFloat(ar[1]);
if(i<=0||i<31)document.ADDUser.PWD.focus();
{
res=false;
}
i=parseFloat(ar[2]);
if(i<=0||i>12)
{
res=false;
}
}
else{
res=false;
}
if(!res){
alert('請輸入 DD/MM/YYYY 日期格式');
}
else{
alert("success");
}
return res;
}
</script>
</HEAD>