validate email format
This commit is contained in:
committed by
Pete Matsyburka
parent
178ee47093
commit
ab810be250
@@ -2,6 +2,8 @@
|
||||
|
||||
module Params
|
||||
class BaseValidator
|
||||
EMAIL_REGEXP = /\A[a-z0-9][\.']?(?:(?:[a-z0-9_-]+[\.\+'])*[a-z0-9_-]+)*@(?:[a-z0-9]+[\.-])*[a-z0-9]+\.[a-z]{2,}\z/i
|
||||
|
||||
InvalidParameterError = Class.new(StandardError)
|
||||
|
||||
def self.call(...)
|
||||
@@ -65,6 +67,14 @@ module Params
|
||||
raise_error(message || "#{key} must follow the #{regexp.source} format")
|
||||
end
|
||||
|
||||
def email_format(params, key, message: nil)
|
||||
return if params.blank?
|
||||
return if params[key].blank?
|
||||
return if params[key].to_s.strip.split(/\s*[;,]\s*/).all? { |email| email.match?(EMAIL_REGEXP) }
|
||||
|
||||
raise_error(message || "#{key} must follow the email format")
|
||||
end
|
||||
|
||||
def unique_value(params, key, message: nil)
|
||||
return unless params.is_a?(Array)
|
||||
return if params.none?
|
||||
|
||||
Reference in New Issue
Block a user