From f4f9c4eeb70634be4480b276341d36d056e775e2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 3 Dec 2019 17:53:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=97=B6=E5=AF=B9=E6=98=B5=E7=A7=B0=E5=92=8C=E5=A7=93?= =?UTF-8?q?=E5=90=8D=E5=81=9Acheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/users/update_account_form.rb | 6 ++---- app/libs/custom_regexp.rb | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/forms/users/update_account_form.rb b/app/forms/users/update_account_form.rb index d4ff25bf7..918e1af50 100644 --- a/app/forms/users/update_account_form.rb +++ b/app/forms/users/update_account_form.rb @@ -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 diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index d7afc61ed..b2f135eae 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -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 \ No newline at end of file