Simple question but I got a headache to solve this game. Example regex.
[a-zA-Z0-9\s]
[whitespace]Stack[whitespace]Overflow - not allow
Stack[whitespace]Overflow - allow
Stack[whitespace]Overflow[whitespace] - not allow
Let me know
Update regex from JG and it's working.
function regex($str)
{
$check = preg_replace('/^[a-zA-Z0-9][a-zA-Z0-9\s]+[a-zA-Z0-9]$|^[a-zA-Z0-9]*$/', "", $str);
if (empty($check)) {
return true;
} else {
return false;
}
}
$str = 'Stack Overflow ';
$validator = regex($str);
if ($validator) {
echo "OK » " .$str;
} else {
echo "ERROR » " . $str;
}