I'm doing a form in php and I need to validate that the fields are not empty. However, when writing EMPTY SPACES in the input, my function is returning a true value. Then the concrete question would be: How to validate that an input does not start with empty spaces but that it accepts them? For example, for the field Name: Jesús Adrían (It is a name composed of two names and it has a space in between).
Currently my role is this:
public static function validarTexto($texto){
if($texto==""){
return false;
}else{
$patron = '/^[a-zA-Z, ]*$/';
if(preg_match($patron,$texto)){
return true;
}else{
return false;
}
}
}
Here is an example of what happens to me:
Thanks for your timely help. Greetings.