我需要一個快速的方式來驗證在PHP或JavaScript是否日期是無效的日期,如(2/31或04/31 - 因爲他們不存在),隨着如果它是否是LEAP年。驗證使用PHP或Javascript的具體日期
我的代碼:
<?php
$month = $_POST["mo"];
$day = $_POST["theDay"];
$yr = $_POST["year"];
if (!isset($_POST['submit'])) { // if page is not submitted; echo form
?>
<h2 style="margin:0; padding:0;">Date Selection</h2>
<span style="color:gray; font-size:0.8em;">By Joseph Dickinson</span>
<FORM method="POST" action="<?php echo $PHP_SELF;?>">
<select name="mo">
<option disabled="disabled">SELECT MONTH</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<select name="theDay">
<option disabled="disabled">SELECT DAY</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="year">
<option disabled="disabled">SELECT YEAR</option>
<option>2011</option>
<option>2010</option>
<option>2009</option>
<option>2008</option>
<option>2007</option>
<option>2006</option>
<option>2005</option>
<option>2004</option>
<option>2003</option>
<option>2002</option>
<option>2001</option>
<option>2000</option>
<option>1999</option>
<option>1998</option>
<option>1997</option>
<option>1996</option>
<option>1995</option>
<option>1994</option>
<option>1993</option>
<option>1992</option>
<option>1991</option>
<option>1990</option>
<option>1989</option>
<option>1988</option>
<option>1987</option>
<option>1986</option>
<option>1985</option>
<option>1984</option>
<option>1983</option>
<option>1982</option>
<option>1981</option>
<option>1982</option>
</select>
<INPUT TYPE="submit" value="Send" name="submit" />
</FORM>
<?
} else {
echo "You chose: " . " ". $month . " ".$day . ", ". $yr;
}
?>
如果有人能在這裏幫助我。
在客戶端和服務器端進行檢查肯定會更好。你使用JavaScript庫嗎? – 2011-01-31 00:09:43