I have a function “isValid” that is responsible for searching for spaces in all variables provided. I want the function to return true if none of the variables contain spaces. Would this be the right approach?
return !(strpos($this->email, " ") || strpos($this->confirm_password1, " ") || strpos($this->handle, " ") || strpos($this->phone, " "));
In order for it to be easily maintainable I would do something like the following:
Note the
=== falseas check forstrpos(). Demo: http://codepad.viper-7.com/0ZgNZq.Note that this only checks for spaces and not possible other whitespace characters. If you want to check for other whitespace characters I would suggest to use a simple regex:
And finally if you really want to do it your original way I would do something like: