return(preg_match('/[A-Z]/', $string) > 0 ? true : false);
echo "<br/><br/>Username is not allowed to have capital letters<br />";
echo "<br/><br/>Password is not allowed to have capital letters<br />";
You definitely can, and in my opinion: you SHOULD in most situations.
The reason I say you should in many situations is because you may be using less memory by not storing the result of the function call in a variable and just checking it in a condition right off the bat.
Of course, in many other situations, you will want to avoid doing this and instead store the result of the function call in an array, such as when you have many conditions to the statement checking the result. In these situations I'd recommend storing the result in a variable because otherwise it would invoke the function numerous times and cause serious overhead.
The above statement is an example of when you don't want to do it, because if the condition is not met in the first "if", myfunc() is called ONCE MORE in the second condition. That's a scenario where you'd want to store the result in a variable and check the variable directly instead.