diff --git a/app/forms/users/apply_authentication_form.rb b/app/forms/users/apply_authentication_form.rb index 986ba6223..2b984fcaa 100644 --- a/app/forms/users/apply_authentication_form.rb +++ b/app/forms/users/apply_authentication_form.rb @@ -4,5 +4,12 @@ class Users::ApplyAuthenticationForm attr_accessor :name, :id_number, :upload_image validates :name, presence: true - validates :id_number, presence: true + validate :validate_ID_number + + + def validate_ID_number + unless id_number =~ User::VALID_NUMBER_REGEX + raise("身份证格式不对") + end + end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 69b48a8cb..0ff967a1a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -164,8 +164,6 @@ class User < ApplicationRecord # validates_format_of :mail, with: VALID_EMAIL_REGEX, multiline: true # validates_format_of :phone, with: VALID_PHONE_REGEX, multiline: true validate :validate_password_length - validate :ID_number, with: VALID_NUMBER_REGE - # validates :nickname, presence: true, length: { maximum: 10 } # validates :lastname, presence: true