You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actually this is quite simple, posting just in case someone is looking for it:
class PhoneNumberValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.nil? || value.empty? || Phoner::Phone.valid?(value)
record.errors.add(attribute, I18n.t('errors.messages.invalid'))
end
end
And then in your model:
class User < ActiveRecord::Base
validates :phone_number, phone_number: true
end
#17 was asking how to use
phone
in model validations. This would be a nice feature but it isn't on the roadmap.The text was updated successfully, but these errors were encountered: