LoginSignup
16
15

More than 5 years have passed since last update.

Rails 電話番号、メールアドレスのバリデーション

Posted at

メールアドレスバリデーション

VALID_EMAIL_REGEX = /\A[\w+-.]+@[a-z\d-.]+.[a-z]+\z/i
validates :email, presence: true, uniqueness: true, format: { with: VALID_EMAIL_REGEX }

電話番号

固定電話と携帯番号(ハイフンなし10桁or11桁)
VALID_PHONE_REGEX = /\A\d{10}$|^\d{11}\z/
validates :phone, presence: true, format: { with: VALID_PHONE_REGEX }

16
15
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
16
15