來源: http://tw.myblog.yahoo.com/davidbulll/article?mid=79&prev=277&next=76
<form onsubmit="return check();">
<input type="text" name="t1">
<input type="submit">
</form>
<script language="javascript">
function check() {
re = /^\d+$/;
if (!re.test(document.forms[0].t1.value)) {
alert("欄位不能空白且只允許輸入數字");
document.forms[0].t1.focus();
return false;
}
return true;
}
function check(thisname) {
if (isNaN(document.getElementById(thisname).value)) {
alert("欄位不能空白且只允許輸入數字");
document.getElementById(thisname).focus();
return false;
}
}
{
if (theForm.name.value == "")
{
alert("請輸入姓名!!");
theForm.name.focus();
return (false);
}
if (theForm.content.value == "")
{
alert("請輸入留言內容!!");
theForm.content.focus();
return (false);
}
return (true);
}
//-->
if (re1.exec(theForm.email.value) == null)
{
alert("你的電子郵件格式不合!");
theForm.email.focus();
return (false);
}
</script>
----------------------------------檢查日期格式
--------------------------------------------------------
<input name="Submit2" type="submit" value="送出" onclick="return check()">
<form onsubmit="return check();">
<input type="text" name="t1">
<input type="submit">
</form>
<script language="javascript">
--------------------------------檢查數字(整數)
function check() {
re = /^\d+$/;
if (!re.test(document.forms[0].t1.value)) {
alert("欄位不能空白且只允許輸入數字");
document.forms[0].t1.focus();
return false;
}
return true;
}
--------------------------------檢查數字可有小數
function check(thisname) {
if (isNaN(document.getElementById(thisname).value)) {
alert("欄位不能空白且只允許輸入數字");
document.getElementById(thisname).focus();
return false;
}
}
--------------------------------檢查是否有填資料
function gbchk(theForm) {
if (theForm.name.value == "")
{
alert("請輸入姓名!!");
theForm.name.focus();
return (false);
}
if (theForm.content.value == "")
{
alert("請輸入留言內容!!");
theForm.content.focus();
return (false);
}
return (true);
}
//-->
----------------------------------檢查是否為MAIL格式
re1 = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/; if (re1.exec(theForm.email.value) == null)
{
alert("你的電子郵件格式不合!");
theForm.email.focus();
return (false);
}
</script>
----------------------------------檢查日期格式
--------------------------------------------------------
<input name="Submit2" type="submit" value="送出" onclick="return check()">
0 意見:
張貼留言