5
5

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 3 years have passed since last update.

[Ruby on Rails] 金額のバリデーション(¥300~¥9,999,999) と テストコード

Last updated at Posted at 2021-02-14

金額のバリデーションで

¥300~¥9,999,999

こういった設定を設ける時の記述

スクリーンショット 2021-02-14 18.17.54.png
 

 
numericalityで整数のみにする設定や数値の最大値、最小値を設定できる。

only_integer: trueで整数値のみに設定。

・ **greater_than_or_equal_to: 300, less_than_or_equal_to: 9999999}**で最小値、最大値を設定。
 
 

ちなみに上記は正規表現半角数字のみというバリデーションもかけている。

  

こちらが金額のテストコード

スクリーンショット 2021-02-14 18.14.16.png

5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?