Rails validations using errors.add -
Rails validations using errors.add - i have separate method in model validate this: validate :validate_id def validate_id errors.add(:base, "id should not blank") if self.project_id.blank? end i need perform validation this: validates_format_of :project_id, :with => /^(?!\d+$)[a-z0-9-_]*$/ which validate letters , numbers underscore , dash , no spaces between them. is there possible way utilize in method validate_id. thanks in advance try: def validate_id errors.add(:base, "id should not blank") if /^(?!\d+$)[a-z0-9-_]*$/.match(self.project_id).nil? end ruby-on-rails ruby-on-rails-3