0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel バリデーション(regexルール)について

Posted at

regexルールの「 | 」の取り扱い

文字列形式でregexルールを指定する際、パイプ記号「 | 」 がルールの区切り文字として使われているので、下記のようにregex内の「 | 」もルールの区切りと判定され、正規表現が途中で途切れてしまうことがありました。

'customize.*.name_for_disp' => 'required|max:100|without_space|regex:/^[^\[\]\|\*\"]+$/'

配列形式で記述すると安心です。

['required', 'max:100', 'without_space', 'regex:/^[^\[\]\|\*\"]+$/']

また、「 | 」をエスケープする方法もあります。

'required|max:100|without_space|regex:/^[^\[\]\\|\*\"]+$/'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?