0

In our HR system i put a validation user have to put a note minimum 8 letters. but what if they don't put they can't punch in. but what they are doing is they are put 8 white space they can punch in :( so i want restrict them to put note avoid white space

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();
}
Developer
  • 145
  • 2
  • 5
  • 20

2 Answers2

6

try trimming the string as in W3 Schools js trim example

i don't have the privilege to comment, that's why i am posting this as an answer...

Hope this helps you..

again as commented by @Julie Pelletier it does not actually fix the issue totally..! :D

Thank you..!

Prashanth Benny
  • 1,523
  • 21
  • 33
  • and you would also provide validation to prevent special characters in order to make it more optimal. check this [link](http://stackoverflow.com/questions/16667329/special-character-validation) to know how to do it. – Prashanth Benny Jul 22 '16 at 05:42
2

Use trim() function

The trim() function removes whitespace and other predefined characters from both sides of a string.


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();
 }
Pradeep
  • 9,667
  • 13
  • 27
  • 34