Skip to content

Commit

Permalink
Renamed allowPipe to allowPipes in AlphaCompleteValidator, updated re…
Browse files Browse the repository at this point in the history
…adme
  • Loading branch information
micheleangioni committed Sep 19, 2016
1 parent 4d89525 commit a42cb94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ if (count($messages)) {

### AlphaCompleteValidator

The AlphaCompleteValidator allows for alphanumeric, underscore, white space, slash, apostrophe, round and square brackets/parentheses and punctuation characters.
The AlphaCompleteValidator allows for alphanumeric, underscore, white space, slash, apostrophe, round and square brackets/parentheses and punctuation characters.
Otionally, it can allow also pipes (|).
Minimum and maximum string lengths can be specified.

```php
Expand All @@ -167,6 +168,7 @@ $validation->add(
'text',
new MicheleAngioni\PhalconValidators\AlphaCompleteValidator (
[
'allowPipes' => true, // Optional
'min' => 6, // Optional
'max' => 30, // Optional
'message' => 'Validation failed.', // Optional
Expand Down
12 changes: 6 additions & 6 deletions src/PhalconValidators/AlphaCompleteValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public function validate(\Phalcon\Validation $validator, $attribute)
{
$value = $validator->getValue($attribute);

$allowPipe = (bool)$this->getOption('allowPipe');
$allowPipe = $allowPipe ? '|' : '';
$allowPipes = (bool)$this->getOption('allowPipes');
$allowPipes = $allowPipes ? '|' : '';

if (!preg_match('/^([-\p{L}*0-9_+!.,:\/;' . $allowPipe . '\\?&\(\)\[\]\{\}\'\"\s])+$/u', $value)) {
if (!preg_match('/^([-\p{L}*0-9_+!.,:\/;' . $allowPipes . '\\?&\(\)\[\]\{\}\'\"\s])+$/u', $value)) {

if ($allowPipe) {
if ($allowPipes) {
$message = $this->getOption('message',
'The value can contain only alphanumeric, underscore, white space, slash, pipe, apostrophe, brackets and punctuation characters');
'The value can contain only alphanumeric, underscore, white spaces, slashes, pipes, apostrophes, brackets and punctuation characters');
} else {
$message = $this->getOption('message',
'The value can contain only alphanumeric, underscore, white space, slash, apostrophe, brackets and punctuation characters');
'The value can contain only alphanumeric, underscore, white spaces, slashes, apostrophes, brackets and punctuation characters');
}

$validator->appendMessage(new Message($message, $attribute, 'AlphaComplete'));
Expand Down
2 changes: 1 addition & 1 deletion tests/ValidatorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function testAlphaCompleteValidatorOkWithPipe()
'text',
new \MicheleAngioni\PhalconValidators\AlphaCompleteValidator (
[
'allowPipe' => true , // Optional
'allowPipes' => true, // Optional
'min' => 5, // Optional
'max' => 100, // Optional
'message' => 'Validation failed.', // Optional
Expand Down

0 comments on commit a42cb94

Please sign in to comment.