Skip to content

Commit

Permalink
Merge pull request #411 from simon-begin/validationUsername
Browse files Browse the repository at this point in the history
[Release] Validation username
  • Loading branch information
Rignon Noël committed Nov 6, 2015
2 parents 37dfeb8 + 510ac52 commit ef25ab6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/Model/Table/UsersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,26 @@ public function validationDefault(Validator $validator)
->notEmpty('username')
->add(
'username',
'unique',
[
'rule' => 'validateUnique',
'provider' => 'table',
'message' => __('This username is already taken.')
]
'unique' => [
'rule' => 'validateUnique',
'provider' => 'table',
'message' => __('This username is already taken.')
],
'custom' => [
'rule' => function ($value) {
if (!preg_match('/^([a-z0-9A-Z_\-.])*$/', $value)) {
return false;
}
return true;
},
'message' => __('Please use only letters (a-z), numbers, periods, and underscore.')
],
'between' => [
'rule' => ['lengthBetween', 3, 16],
"message" => __('Please use between 3 and 16 characters.')
]
]
);

$validator
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Users/register.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="form-group clearfix">
<?= $this->Form->label('username', __('Choose your username'), ['class' => 'col-sm-2 control-label']); ?>
<div class="col-sm-10">
<?= $this->Form->input('username', ['label' => false, 'placeholder' => __('Username'), 'autocomplete' => 'off']); ?>
<?= $this->Form->input('username', ['pattern' => '[a-zA-Z0-9_.-]{3,16}', 'title' => __('Letters (a-z), numbers, periods, underscore, and between 3 and 16 characters'), 'label' => false, 'placeholder' => __('Username'), 'autocomplete' => 'off']); ?>
</div>
</div>
<br/>
Expand Down

0 comments on commit ef25ab6

Please sign in to comment.