Skip to content

Commit 45f798e

Browse files
authored
Support different wraps, fixed return of function
1 parent a12791c commit 45f798e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/RegexValidator.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
<?php
22

3-
43
namespace MarketFlow\Yii2\Validators;
54

6-
75
use \yii\validators\Validator;
86

97
class RegexValidator extends Validator
108
{
11-
public $wrap = false;
9+
public $wrap = '';
1210

1311
protected function validateValue($value)
1412
{
1513
try {
16-
preg_match($this->wrap ? "/$value/" : $value, '');
14+
preg_match($this->wrap . $value . $this->wrap, '');
1715
} catch (\Exception $e) {
18-
return \Yii::t('app', 'Invalid regex for {attribute}');
16+
return [\Yii::t('app', 'Invalid regex for {attribute}'), []];
1917
}
20-
}
2118

22-
23-
}
19+
return null;
20+
}
21+
}

0 commit comments

Comments
 (0)