2016-07-22 46 views
0

在我们的人力资源系统中,我把验证用户必须至少放8个字母。但如果他们不把他们不能打卡,但他们在做什么是他们把8的白色空间,他们可以在冲:(所以我想限制他们把注意避免空白PHP表单验证最小字符需要避免空格?

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(); 
} 
+2

这就好比修理化油器用绷带。用户会注意到他们可以放8个点或其他任何东西。 –

+0

为什么它被标记为JavaScript?你是否也想执行客户端检查? – Arnauld

回答

2

使用修整()函数

装饰()函数从字符串的两侧去除空白和其他预定义字符。


http://www.w3schools.com/php/func_string_trim.asp

 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(); 
} 
6

尝试微调串W3 Schools js trim example

我没有权限发表评论,这就是为什么我张贴此作为一个答案......

希望这有助于你..

再次作为com由@Julie Pelletier改编,它并没有完全解决这个问题。 :D

谢谢..!

+0

,并且您还将提供验证以防止出现特殊字符以使其更加优化。检查这个 [链接](http://stackoverflow.com/questions/16667329/special-character-validation)知道如何做到这一点。 –