I have some values fetched from a TextField, stored to a Array and I'm going to filter it through a for loop. I want to keep out symbols like []{}; and so on, while also allowing whitespaces and the - for some words. So, I constructed this:
$Regex = '/^[a-zA-ZÀ-ÖØ-öø-ÿ0-9 \-]*$/';
$FieldRegex = (preg_match($Regex, $Field[$counter]));
for ($counter = 0; $counter <= 6; $counter++){
if(!$FieldRegex) {
echo '<script language="javascript">';
echo 'alert("Only numbers, letters and - are allowed!")';
echo '</script>';
header("Location:{$_SERVER['HTTP_REFERER']}");
break;
exit;
} else {
if($counter == 6){
$Proceed1 = true;
}
The problem that persists through each try is that anything that I try to submit, it won't give me any message and doesn't save to the DB, even if it fits within the regex parameters.
I've been wrapping my head around it but can't seem to find the answer.
What am I doing wrong?
/uflag. A special option is the /u which turns on the Unicode matching mode, instead of the default 8-bit matching mode.$FieldRegex = (preg_match($Regex, $Field[$counter]));inside the loop. If you don't,$counterwill be undefined.'/^[a-zA-ZÀ-ÖØ-öø-ÿ0-9 \-]$+/u'but it still doesn't work. Doesn't return any input at all."/\x{0080}/u"(note double quotes). PHP strings will not correctly handle this use case.