Hi,

i have this issue when i use a RegExp on several fields, an "0" is accepted, even when i set a minimum of characters.

CommentFileSizeAuthor
#2 webform_validation.validators.zip2.83 KBMariano

Comments

Mariano’s picture

Hi, this looks like a logical problem on line 304 of the file webform_validation.validators.inc:

      case "regex":
        $regex = $rule['data'];
        foreach ($items as $key => $val) {
          if ($val && (!preg_match("/$regex/", $val))) {
            $errors[$key] = _webform_validation_i18n_error_message($rule);
          }
        }
        return $errors;
        break;

The IF will never validate if the value of $val is 0 (which is taken from the form field), because it takes it as FALSE. Since what the code is trying to check is if the variable has any value, I believe that it should be enclosed by the function isset().

There are actually a lot of validators using the same approach.

Mariano’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new2.83 KB

Submitting a patched webform_validation.validators.inc file

svendecabooter’s picture

Status: Patch (to be ported) » Fixed

Good catch!
I have updated the code so it only checks for empty strings to skip validation. All other entered values should be always be validated...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.