forgeplus/app/forms/organizations/create_form.rb

19 lines
936 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Organizations::CreateForm < BaseForm
NAME_REGEX = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*$/ #只含有数字、字母、下划线不能以下划线开头和结尾
attr_accessor :name, :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, :nickname, :original_name
validates :name, :nickname, :visibility, presence: true
validates :name, :nickname, length: { maximum: 100 }
validates :location, length: { maximum: 50 }
validates :description, length: { maximum: 200 }
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能以数字或字母开头仅支持横杠、下划线、点三种符号不允许符号连续排列长度4-50个字符" }
validate do
check_name(name) unless name.blank? || name == original_name
end
def check_name(name)
raise "组织账号已被使用." if Owner.where(login: name.strip).exists?
end
end