-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathRegex.php
More file actions
54 lines (48 loc) · 1.36 KB
/
Copy pathRegex.php
File metadata and controls
54 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Regex
*
* @category AcsiWidget\Renderer\JqueryValidate\Rule
* @package AcsiWidget\Renderer\JqueryValidate\Rule
* @copyright 2016 ACSI Holding bv (http://www.acsi.eu)
* @version SVN: $Id: $
*/
namespace StrokerForm\Renderer\JqueryValidate\Rule;
use Zend\Form\ElementInterface;
use Zend\Validator\ValidatorInterface;
use Zend\Validator\Regex as RegexValidator;
class Regex extends AbstractRule
{
/**
* Get the validation rules
*
* @param ValidatorInterface $validator
* @param ElementInterface $element
* @return array
*/
public function getRules(ValidatorInterface $validator, ElementInterface $element = null)
{
/**@var RegexValidator $validator */
$pattern = $validator->getPattern();
preg_match('/\/(.*)\/[imosxg]{0,}/', $pattern, $matches);
return ['regex' => $matches[1]];
}
/**
* Get the validation message
*
* @param ValidatorInterface $validator
* @return array
*/
public function getMessages(ValidatorInterface $validator)
{
return ['regex' => $validator->getMessageTemplates()[\Zend\Validator\Regex::NOT_MATCH]];
}
/**
* @param ValidatorInterface $validator
* @return bool
*/
public function canHandle(ValidatorInterface $validator)
{
return $validator instanceof RegexValidator;
}
}