Last active
February 17, 2016 06:32
-
-
Save lasershow/63341ef89ddc9cc91185 to your computer and use it in GitHub Desktop.
【初心者】railsのvalidatesのpresenceでエラーメッセージが重複するのを防ぐ方法 ref: http://qiita.com/lasershow/items/0229855720aaf2be5fc8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
・メールアドレスが入力されていません。 | |
・メールアドレスが不正な値です。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
validates :email, format: {with: VALID_EMAIL_REGEX}, allow_blank: true | |
validates :email, presence: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
・メールアドレスが入力されていません。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates :email, | |
presence: true, | |
format: {with: VALID_EMAIL_REGEX, allow_blank: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment