Skip to content

Inconsistent Form::PATTERN #104

@MartinSadovy

Description

@MartinSadovy

When I use back references in pattern rule (Form::PATTERN), it creates different behaviour on client side and server side in validation, because in Validator class, input pattern is bracked.

Example pattern: (.)\1{2,}
Different back reference:

  • Client side is \1
  • Server side is \2

Before I create PR, I would like to know, why pattern is bracked. There are two options: remove these bracket, or add to brackes (here, here).

use Nette\Forms\Form;

$form = new Form;
#$form->getElementPrototype()->novalidate = true;  // uncomment = validate by server side

$form->addText('name', 'Name:')
    ->addRule(
        Form::PATTERN, 
        'Please, write text with three same characters consecutively', 
        '(.)\1{2,}'
    );
$form->addSubmit('send', 'Register');
if ($form->isSuccess()) {
    echo '<h2>Form was submitted and successfully validated</h2>';

}
echo $form; // renders the form

reference bug reporting in czech forum: https://forum.nette.org/cs/25332-invert-regularniho-vyrazu#p168360

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions