Form::PATTERN, from Nette 2.2, doesnt work?

Notice: This thread is very old.
mcmatak
Member | 490
+
0
-

in past i used this pattern type

[{
    "op": ":filled",
    "msg": "Číslo kuponu musí být vyplněno!"
}, {
    "op": ":equal",
    "rules": [{
        "op": ":pattern",
        "msg": "Při zadávání kuponu ze slevového portálu NakupvAkci.cz musí být číslo kuponu zadáno ve tvaru NAK00032cn nebo NAK00002ggwfpttg!",
        "arg": "/^NAK[0-9a-z]{7,13}$/i"
    }],
    "control": "idCouponType",
    "arg": 7
}, {
    "op": ":equal",
    "rules": [{
        "op": ":pattern",
        "msg": "Při zadávání kuponu ze slevového portálu SlevaDne.cz musí být číslo kuponu zadáno ve tvaru 100118968455!",
        "arg": "/^[0-9]{12}$/i"
    }],
    "control": "idCouponType",
    "arg": 12
}]

but from version 2.2 it doesnt work

“arg”: “/^[0–9]{12}$/i” where is problem with this?

even without case insesitive switcher it doesnt work

“arg”: “/^[0–9]{12}$/”

why?

matopeto
Member | 395
+
0
-

try only “[0–9]{12}”

nette adding ^ and $:

<?php
	/**
	 * Matches control's value regular expression?
	 * @return bool
	 * @internal
	 */
	public static function validatePattern(TextBase $control, $pattern)
	{
		return (bool) Strings::match($control->getValue(), "\x01^($pattern)\\z\x01u");
	}
?>

if you have to use custom regex you can try use DEPRICATED REGEXP validator, it don't add anything to your regex pattern:

<?php
	/** @deprecated */
	public static function validateRegexp(TextBase $control, $regexp)
	{
		trigger_error('Validator REGEXP is deprecated; use PATTERN instead (which is matched against the entire value and is case sensitive).', E_USER_DEPRECATED);
		return (bool) Strings::match($control->getValue(), $regexp);
	}
?>
mcmatak
Member | 490
+
0
-

i know, there was some changes, bcs without slashes it works, it is BC BREAK

David Grudl
Nette Core | 8082
+
0
-

It is not BC break, because it never worked as you write.

mcmatak
Member | 490
+
0
-

maybe more than one year, trust me no chance to dont know it, hundreds of people test this function every day,

i would know it in a few minutes that something is wrong

and as i see in history last commit on this row was

04 Nov, 2013

old line

- ->addRule($form::REGEXP, _t('couponsBox/v/rgxDeactivationCode', 1, array('%couponType%' => $couponType->name, '%number%' => $couponType->type->exampleDeactivationCode)), "/" . $couponType->type->rgxDeactivationCode . "/");

new line

+ ->addRule($form::REGEXP, _t('couponsBox/v/rgxDeactivationCode', 1, array('%couponType%' => $couponType->name, '%number%' => $couponType->type->exampleDeactivationCode)), "/" . $couponType->type->rgxDeactivationCode . "/i");

no changes from that time, but after upgrade to nette 2.2 i need to remove the slashes to get it work

mcmatak
Member | 490
+
0
-

it is missunderstanding between old function of REGEXP and PATTERN

i had code prepared for nette 2.2 some months ago, but i deployed now, so thats why i didnt realized that regexp before and pattern is different

so resolved thanks