javascript 日期格式驗證代碼

來源:互聯網
上載者:User

javascript教程 日期格式驗證代碼
<form id="myfm" name="myfm" method="post" action="?">
<table class="table_list" >

 <caption>
 增加價格
 </caption>
 
 <tr>
   <td class="align_c"><span class="paginator">年-月-日</span>:<span class="red">*</span></td>
   <td >
     <label>
     <input name="dates" type="text" size="20" />
    &nbsp; <span class="STYLE1">&quot;2010-04-04&quot; </span></label></td>
  </tr>
 <tr>
   <td class="align_c"><span class="paginator">平均價格:<span class="red">*</span></span></td>
   <td><label>
     <input name="price" type="text" size="10" />
     <span class="STYLE1">658</span></label></td>
  </tr>
 <tr>
   <td width="20%" class="align_c">&nbsp;</td>
   <td width="80%" ><label>
     <input type="submit" name="Submit"  onclick="return IsDate();" value="提交" />
     &nbsp;&nbsp;&nbsp;
     <input type="reset" name="Submit2" value="重設" />
   </label></td>
  </tr>
</table>
</form>
<script language="javascript">
 function IsDate() {
   var regex = new RegExp("^(?:(?:([0-9]{4}(-|/)(?:(?:0?[1,3-9]|1[0-2])(-|/)(?:29|30)|((?:0?[13578]|1[02])(-|/)31)))|([0-9]{4}(-|/)(?:0?[1-9]|1[0-2])(-|/)(?:0?[1-9]|1\d|2[0-8]))|(((?:(\d\d(?:0[48]|[2468][048]|[13579][26]))|(?:0[48]00|[2468][048]00|[13579][26]00))(-|/)0?2(-|/)29))))$"); 
   var dateValue = myfm.dates.value; 
     var datePrice = myfm.price.value;
   if (!regex.test(dateValue) )
     { 
     alert("日期必須按2010-1-11或2010-01-01書寫格式");  
     myfm.dates.value = "";  
     myfm.dates.focus();  
     return false; 
    }
   else if( isNaN( datePrice ) )
   {
    alert("均價必須為數字哦");  
    myfm.price.value = "";  
     myfm.price.focus();  
     return false; 
   }  
  }
</script> 
 本站原創文章轉載註明來自www.111cn.net
*/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.