I am building a form in PHP that requires that the field values only contain letters and whitespace(s).
There are a few small twists on this problem though:
TRIM()
function)Examples of input & output:
INPUTConQueso, Cheese
OUTPUTConQueso Cheese
INPUT0 Eddie Murphy-Washington, the 3rd .
OUTPUTEddie Murphy Washington the rd
Simply replace [^a-z]+
with space. And at the end, do a trim()
.
$text = trim(preg_replace('/[^a-z]+/i', ' ', $text));