首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Php表单验证最小字符需要避免空白?

Php表单验证最小字符需要避免空白?
EN

Stack Overflow用户
提问于 2016-07-22 05:24:51
回答 2查看 148关注 0票数 0

在我们的人力资源系统中,我给一个验证用户写了至少8个字母的注释。但是,如果他们不放,他们就不能插嘴。但他们正在做的是,他们有8个空格,他们可以输入:(所以我希望限制他们放置注意,避免空白。

代码语言:javascript
复制
if(empty($openPunch)){

            $currentTime = $req->time;
            if (strtotime($currentTime) >= strtotime('09:30')){
                if(strlen($req->note) < 8){
                $time = (strtotime($currentTime) - strtotime('09:30'));
                $minutes = floor($time / 60);
                $minute = $minutes%60;
                $hours = floor($time / 3600);
                return new IceResponse(IceResponse::ERROR,"Today you are late ".$hours.":".$minute." Hours    You Can't Punch in without Fill the Correct Reason");

    }
    }

    $openPunch = new Attendance();
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-07-22 05:32:29

使用trim()函数

函数从字符串的两边删除空格和其他预定义字符。

trim.asp

代码语言:javascript
复制
      if(empty($openPunch)){

        $currentTime = $req->time;
        if (strtotime($currentTime) >= strtotime('09:30')){
            if(strlen(trim($req->note)) < 8){
            $time = (strtotime($currentTime) - strtotime('09:30'));
            $minutes = floor($time / 60);
            $minute = $minutes%60;
            $hours = floor($time / 3600);
            return new IceResponse(IceResponse::ERROR,"Today you are late ".$hours.":".$minute." Hours    You Can't Punch in without Fill the Correct Reason");

     }
    }

     $openPunch = new Attendance();
 }
票数 2
EN

Stack Overflow用户

发布于 2016-07-22 05:31:56

尝试像在W3 Schools js trim example中那样裁剪字符串

我没有特权发表评论,这就是为什么我把这个作为回答.

希望这能帮到你..。

同样,正如@Julie Pelletier评论的那样,它实际上并没有完全解决这个问题..!

谢谢..!

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38518788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档