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();
}
2
  • 2
    This is like repairing a carburetor with a bandaid. Users will notice they can put 8 dots or anything else instead. Commented Jul 22, 2016 at 5:28
  • Why is it flagged as javascript? Do you want to perform a client-side check as well? Commented Jul 22, 2016 at 5:34

2 Answers 2

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..!

Sign up to request clarification or add additional context in comments.

1 Comment

and you would also provide validation to prevent special characters in order to make it more optimal. check this link to know how to do it.
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();
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.