Skip to content

Regex rule - unexpected warning with comma character #23

@Vandervir

Description

@Vandervir

Hey hey,
I noticed some problem while using regex that contains comma.

when you have rule like this: regex:/^([a-zA-Z\,]*)$/
Final regex will be /^([a-zA-Z\

And that will result in following warning: Warning: preg_match(): No ending delimiter '/' found in ../rakit/validation/src/Rules/Regex.php on line 18

That is main problem with parseRule method, that splits params no mater what.

instead:

protected function parseRule($rule)
{
$exp = explode(':', $rule, 2);
$rulename = $exp[0];
$params = isset($exp[1])? explode(',', $exp[1]) : [];
return [$rulename, $params];
}

should be something like this:

protected function parseRule($rule)
{
$exp = explode(':', $rule, 2);
$rulename = $exp[0];
if ($rulename !== 'regex') {
$params = isset($exp[1])? explode(',', $exp[1]) : [];
} else {
$params = [$exp[1]];
}
return [$rulename, $params];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions