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

バリデーションの種類について

Posted at

電話番号のバリデーションについて

# 電話番号(ハイフンなし10桁)
/\A\d{10}\z/

# 携帯番号(ハイフンなし11桁)
/\A\d{11}\z/

# 携帯番号(ハイフンなし10桁or11桁)
/\A\d{10,11}\z/

実際の記述はこんな感じ。

app/models/purchase_shipping.rb
    validates :phone_number, format: { with: /\A\d{10,11}\z/, message: "PhoneNumber must be 10or11 digit Half-width numbers" }

その他正規表現を使用したバリデーションの種類について下記リンクの記事がすごいわかりやすかった。
https://gist.github.com/nashirox/38323d5b51063ede1d41

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