Spree::User.class_eval do
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
validates :password, :format => {
:with => /^(?=.*[A-Z])(?=.[#!@$&?<>',\[\]}{=\-)(^%`~+.:;_])(?=.*[0-9])(?=.*[a-z])[^ ]{8,}$/,
:multiline => true,
message: "Password should be a minimum of 8 characters long," \
"contain both uppercase and lowercase characters, at" \
"least one digit, spaces not allowed and one special character "
}, if: :password
validates :email, :format => {
:with => /[^@]+[@][\S]+[.][\S]+/,
:multiline => true,
}
validates :phone_num, presence: true
before_validation :parse_phone_num
validate :valid_phone_number
has_one_attached :profile_image
has_one :wishlist, dependent: :destroy
has_and_belongs_to_many :spree_roles, join_table: 'spree_roles_users', class_name: 'Spree::Role'
# has_many :products, class_name: 'Spree::Product', through: :wishlists, dependent: :destroy
private
def parse_phone_num
@phone = Phonelib.parse(phone_num)
self.phone_num = @phone.sanitized
end
def valid_phone_number
unless Phonelib.valid?(phone_num)
errors.add(:phone_num, "Invalid or Unrecognized Phone Number")
end
end
end
This is the code which I tried