Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions plugins/baser-core/src/Model/Table/UsersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,25 @@ public function validationDefault(Validator $validator): Validator
->scalar('real_name_1')
->maxLength('real_name_1', 50, __d('baser_core', '名前[姓]は50文字以内で入力してください。'))
->requirePresence('real_name_1', 'create', __d('baser_core', '名前[姓]を入力してください。'))
->notEmptyString('real_name_1', __d('baser_core', '名前[姓]を入力してください。'));
->notEmptyString('real_name_1', __d('baser_core', '名前[姓]を入力してください。'))
->add('real_name_1', [
'noWhitespace' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カスタムでバリデーションルールを実装するより、regexで対応できるのではと考えていますがどうでしょうか?
コアでもregexが多用されている印象があり、複雑なロジックの場合だけカスタムでバリデーションルールが実装されている気がします。

3.8系みたいですが以下がまとまっています。
https://qiita.com/azukiazusa/items/9e8bbe461bdbc7ee572c

'rule' => function ($value) {
return !preg_match('/[  ]/u', $value);
},
'message' => __d('baser_core', '名前[姓]に半角・全角スペースは使用できません。')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名前[姓]に半角・全角スペースは使用できません。

上記はすでに多言語化、対応ファイルが追記されているのかと考えましたが、まだのようなので、以下ファイルに多言語化対応などを追記する必要がありそうです。

例:

  • plugins/baser-core/resources/locales/baser_core.pot
  • plugins/baser-core/resources/locales/en/baser_core.po

なお別prで対応いただく形であれば問題ないと思います。

]]);
$validator
->scalar('real_name_2')
->maxLength('real_name_2', 50, __d('baser_core', '名前[名]は50文字以内で入力してください。'))
->allowEmptyString('real_name_2');
->allowEmptyString('real_name_2')
->add('real_name_2', [
'noWhitespace' => [
'rule' => function ($value) {
return !preg_match('/[  ]/u', $value);
},
'message' => __d('baser_core', '名前[名]に半角・全角スペースは使用できません。')
]]);
$validator
->scalar('nickname')
->maxLength('nickname', 255, __d('baser_core', 'ニックネームは255文字以内で入力してください。'))
Expand Down
Loading