duancai9010 2016-01-09 16:49
浏览 287
已采纳

如何设置出生日期输入的验证规则

How can I set date of birth validations for a registration form?

I tried comparing the dob entered with the current date but it didn't work.

if (date("d/m/y") > $dob){
    echo "impossible";
}

or better how can i make it so that the user doesn't have the option to pick a date that hasn't come yet.

Also how can i compare the dates to not allow someone under 12 to join my website?

  • 写回答

5条回答 默认 最新

  • dsfbnhc4373 2016-01-09 23:59
    关注

    I managed to do this seeing as i don't want to use jquery for this

    if (isset($_POST['button'])){
       $dob = $_POST['dob'];
    
       echo $dob."<br>".date("o-m-d");
    
       if (date("o-m-d") < $dob){
           echo "<br>invalid dob";
       } else echo "<br>valid dob";
    }
    

    When I pick 31/01/2016 the script gives

    2016-01-31
    2016-01-09
    invalid dob
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题