@Marleen is correct. You have to many parameters in your noSpecialChars
function. I have a similar function in my CI4 app that looks like this:
public function alpha_numeric_punct_german(string $str, ?string &$error = null)
{
// M = Math_Symbol, P = Punctuation, L = Latin
if ((bool) preg_match('/^[^\p{M}\p{P}\p{L}0-9 ~!#$€%\&\*\-\–_+=|:.,„“"`´\']+$/ium', $str)) {
$error = 'Contains illegal characters';
return false;
}
return true;
}
The $error
argument is optional. You only have to pass string $fields
and array $data
if you want to pass additional data to your validation rule like for example in in_list[2,5]
or valid_date[d.m.Y]
.