gpt4 book ai didi

php - 在 codeigniter 中为日期表单输入字段

转载 作者:行者123 更新时间:2023-11-30 05:58:06 25 4
gpt4 key购买 nike

是否有 codeigniter 提供任何 js 类来从用户那里获取表单字段中的日期值?我正在 codeigniter 的用户指南中搜索,但找不到此类。

目前我正在使用另一个 js 类来获取日期值。

最佳答案

您可以扩展 Form_validation 并运行回调

// Is this a valid date?
function valid_date($str)
{
$CI =& get_instance();
$CI->form_validation->set_message('valid_date', 'Sorry - the %s field must be a date with format dd-mm-yyyy');

if (preg_match("/^(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[012])-(19|20)[0-9]{2}$/", $str))
{
$arr = explode("-", $str);
$yyyy = $arr[2];
$mm = $arr[1];
$dd = $arr[0];
if (is_numeric($yyyy) && is_numeric($mm) && is_numeric($dd))
{
return checkdate($mm, $dd, $yyyy);
}
else
{
return false;
}
}
else
{
return false;
}
}

这样你就可以在字段上运行验证,不管用户是否打开了 JS

关于php - 在 codeigniter 中为日期表单输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10578853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com