保存用户信息时对昵称和姓名做check

chromesetting
cxt 5 years ago
parent de6056cdbb
commit f4f9c4eeb7

@ -5,8 +5,8 @@ class Users::UpdateAccountForm
attr_accessor :nickname, :name, :show_realname, :gender, :location, :location_city,
:identity, :student_id, :technical_title, :school_id, :department_id
validates :nickname, presence: true, length: { minimum: 2, maximum: 20 }
validates :name, presence: true, length: { minimum: 2, maximum: 10 }
validates :nickname, presence: true, length: { minimum: 2, maximum: 20 }, format: { with: CustomRegexp::NICKNAME, message: "昵称2-20位中英文、数字及下划线" }
validates :name, presence: true, length: { minimum: 2, maximum: 10 }, format: { with: CustomRegexp::LASTNAME, message: "姓名2-10位中英文、数字" }
validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] }
validates :location, presence: true
validates :location_city, presence: true
@ -14,8 +14,6 @@ class Users::UpdateAccountForm
validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' }
validates :student_id, presence: true, if: -> { identity.to_s == 'student' }
validates :school_id, presence: true
validates_format_of(:nickname, with: /^[\u4e00-\u9fa5_a-zA-Z0-9]+$/, message: "2-20位中英文、数字及下划线")
validates_format_of(:name, with: /^[a-zA-Z\u4e00-\u9fa5]+$/, message: "2-10位中英文")
validate :check_school_exist
def check_school_exist

@ -1,4 +1,6 @@
module CustomRegexp
PHONE = /1\d{10}/
EMAIL = /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/
LASTNAME = /^[a-zA-Z0-9\u4e00-\u9fa5]+$/
NICKNAME = /^[\u4e00-\u9fa5_a-zA-Z0-9]+$/
end
Loading…
Cancel
Save