試圖使用jQuery來做到這一點,我發現了一個名爲「真正的日期驗證」的插件。我似乎無法正確實施它。驗證無效日期/閏年
任何人都可以幫助我嗎?試圖驗證日期2-31- [whateveryear]不應該工作,以及閏年...
<?php
$month = $_POST["mo"];
$day = $_POST["theDay"];
$yr = $_POST["year"];
if (!isset($_POST['submit'])) { // if page is not submitted; echo form
?>
<script type="text/javascript" src="jquery.js"> </script>
<script type="text">
$(document).ready(function() {
var month = $('#mo').val();
var day = $('#tDay').val();
var year = $('#tYear').val();
var date = new Date(month+"/"+day+"/"+year);
if(day == "29" && month == "02") {
if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
return true
} else { return false; }
} else if(month == (date.getMonth()+1) && day == date.getDate() && year == date.getFullYear()) {
return true;
} else { return false; }
});
</script>
<h2 style="margin:0; padding:0;">Date Selection</h2>
<FORM method="POST" action="<?php echo $PHP_SELF;?>">
<select name="mo" id="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" id="tDay">
<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" id="tYear">
<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;
}
?>
確實$ PHP_SELF即使沒有register_globals工作?無論如何,用`$ _SERVER ['PHP_SELF']` – ThiefMaster 2011-01-31 16:24:51