From 779c380c955191b1f3cc651a9caee6e4275aaa61 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sun, 29 Sep 2019 10:43:51 +0800 Subject: [PATCH] 1 --- app/models/user.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index d74ea1b09..5de3e263c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -164,9 +164,8 @@ 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 :validate_ID_number + validate :validate_ID_number #validates_format_of :ID_number, with: VALID_NUMBER_REGEX, multiline: true, message: "身份证号格式不对" - validates :ID_number, format: {with: VALID_NUMBER_REGEX, multiline: true, message: "身份证格式不对"} # validates :nickname, presence: true, length: { maximum: 10 } # validates :lastname, presence: true @@ -621,6 +620,12 @@ class User < ApplicationRecord raise("密码长度不能低于#{MIX_PASSWORD_LIMIT}位") end end + + def validate_ID_number + if ID_number.present? && ID_number =~ VALID_NUMBER_REGEX + raise("身份证格式不对") + end + end end