1
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?

More than 1 year has passed since last update.

laravel uuidの形式チェックを行うバリデーションルール

Posted at

概要

laravelのバリデーションルールにて、正規表現を用いてuuidの形式をチェックするバリデーションルールを考えたので簡単にまとめておく。

内容

regexのルールを使って正規表現を用いて文字列形式のチェックを行う。

$request->validate([
    'uuid' => ['required', 'regex:/([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})/'],
]);

uuidは8桁-4桁-4桁-4桁-12桁の形式のため、それぞれ取りうる値を正規表現で表してみた。

参考文献

1
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
1
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?