Skip to content

Commit

Permalink
Support different wraps, fixed return of function
Browse files Browse the repository at this point in the history
  • Loading branch information
joester89 authored Feb 9, 2017
1 parent a12791c commit 45f798e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/RegexValidator.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<?php


namespace MarketFlow\Yii2\Validators;


use \yii\validators\Validator;

class RegexValidator extends Validator
{
public $wrap = false;
public $wrap = '';

protected function validateValue($value)
{
try {
preg_match($this->wrap ? "/$value/" : $value, '');
preg_match($this->wrap . $value . $this->wrap, '');
} catch (\Exception $e) {
return \Yii::t('app', 'Invalid regex for {attribute}');
return [\Yii::t('app', 'Invalid regex for {attribute}'), []];
}
}


}
return null;
}
}

0 comments on commit 45f798e

Please sign in to comment.