Skip to content

Instantly share code, notes, and snippets.

@lesniakania
Created February 16, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesniakania/9977235274026833745c to your computer and use it in GitHub Desktop.
Save lesniakania/9977235274026833745c to your computer and use it in GitHub Desktop.
class UserValidator
include ActiveModel::Validations
def self.fields
[:username, :password, :email, :phone, :age]
end
attr_accessor(*fields)
validates :username,
length: { within: 5..20 },
uniqueness: true,
format: { with: /\A\w*\z/ }
validates :password, length: { within: 5..20 }
validates :email, format: { with: /.+@.+\..+/i }
validates :phone, format: { with: /\+48/ }
validates :age, numericality: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment