PHP 日期驗證:改進的方法
問題:
問題:我遇到困難使用正規表示式(regex) 實作PHP 日期驗證。我目前的正規表示式無法正常運作。你能提供更可靠的解決方案嗎?
答案:<code class="php">$test_date = '03/22/2010'; $test_arr = explode('/', $test_date); if (checkdate($test_arr[0], $test_arr[1], $test_arr[2])) { // Valid date ... }</code>
<code class="php">$test_date = '03/22/2010'; $test_arr = explode('/', $test_date); if (count($test_arr) == 3) { if (checkdate($test_arr[0], $test_arr[1], $test_arr[2])) { // Valid date ... } else { // Problem with dates ... } } else { // Problem with input ... }</code>
以上是如何在不使用正規表示式的情況下執行準確的 PHP 日期驗證的詳細內容。更多資訊請關注PHP中文網其他相關文章!