Its expression contains the wildcard character *
. The * quantifier corresponds to the previous element ZERO or more times. Thus, even if the string does not contain any unauthorized character, the matcher will simply say: zero combines.
It’s right to use +
matching of preceded characters (NOT ALLOWED) once or more.
Was also missing /
limits at the end
Your corrected expression:
if(!preg_match("/^[a-zA-Z]+$/",$name)||!preg_match("/^[a-zA-Z]+$/",$title)||!preg_match("/^[a-zA-Z]+$/",$text)){
A suggestion
$string=$name.$title.$text;
if(!preg_match("/^[a-z]+?$/i", $string)){
header("location: ../contato.php?contato=invalidcharacters");
exit();
}
From the beginning ( ^
) at the end ( $
) of the string ONLY the amount can exist ( +?
) of letters from a to z ( [a-z]
) uppercase or minuscule ( i
).
( !
) is the negative of the expression condition, that is, if the string does not consist only of uppercase or minuscule letters.
What string is not passing? Do not allow white spaces?
– Sergio
was not allowing anything
– Adriano Back