Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Would you duplicate the validation's regex, or reference a constant?
class User
field :username, :type => String
validates :username, :format => { :with => /\A[[:print:] ]{3,20}\Z/ }
end
class ScoreCard
belongs_to :user
field :username, :type => String
validates :username, :format => { :with => /\A[[:print:] ]{3,20}\Z/ }
end
class User
USERNAME_REGEX = /\A[[:print:] ]{3,20}\Z/
field :username, :type => String
validates :username, :format => { :with => USERNAME_REGEX }
end
class ScoreCard
belongs_to :user
field :username, :type => String
validates :username, :format => { :with => User::USERNAME_REGEX }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment