validate email/phone submission format
This commit is contained in:
@@ -59,6 +59,14 @@ module Params
|
||||
raise_error(message || "#{key} must be a #{type}")
|
||||
end
|
||||
|
||||
def format(params, key, regexp, message: nil)
|
||||
return if params.blank?
|
||||
return if params[key].blank?
|
||||
return if regexp.match?(params[key].to_s)
|
||||
|
||||
raise_error(message || "#{key} must follow the #{regexp.source} format")
|
||||
end
|
||||
|
||||
def in_path(params, path = [])
|
||||
old_path = @current_path
|
||||
|
||||
|
||||
@@ -60,7 +60,10 @@ module Params
|
||||
|
||||
type(submitter_params, :name, String)
|
||||
type(submitter_params, :email, String)
|
||||
format(submitter_params, :email, /@/, message: 'email is invalid')
|
||||
type(submitter_params, :phone, String)
|
||||
format(submitter_params, :phone, /\A\+\d+\z/,
|
||||
message: 'phone should start with +<country code> and contain only digits')
|
||||
type(submitter_params, :values, Hash)
|
||||
boolean(submitter_params, :send_email)
|
||||
boolean(submitter_params, :send_sms)
|
||||
|
||||
Reference in New Issue
Block a user