2016-07-22 12 views
0

私たちのHRシステムでは、検証ユーザーは最低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

であり、さらに最適なものにするために、特殊文字を防ぐための検証も行います。この方法を知るには、 [link](http://stackoverflow.com/questions/16667329/special-character-validation)をチェックしてください。 –

関連する問題