class ValidationProfiler::Rules::EmailValidationRule
Constants
- REGEX
Public Instance Methods
error_message(field, attributes = {}, parent = nil)
click to toggle source
# File lib/validation_profiler/rules/email_validation_rule.rb, line 7 def error_message(field, attributes = {}, parent = nil) field_name = field.to_s if parent != nil field_name = "#{parent.to_s}.#{field.to_s}" end #check if a custom error message has been specified in the attributes if attributes[:message] == nil #no custom error message has been specified so create the default message. "#{field_name} is not a valid email address" else attributes[:message] end end
multiple_valid?(value)
click to toggle source
# File lib/validation_profiler/rules/email_validation_rule.rb, line 45 def multiple_valid?(value) return false unless value.is_a? String value.split(/ *[,|;] */).each do |val| next if val =~ REGEX return false end true end
validate(obj, field, attributes = {}, parent = nil)
click to toggle source
# File lib/validation_profiler/rules/email_validation_rule.rb, line 23 def validate(obj, field, attributes = {}, parent = nil) #attempt to get the field value from the object field_value = get_field_value(obj, field) if !is_required?(field_value, attributes) return true end if attributes[:multiple] == true return multiple_valid?(field_value) end #validate the value against the regex if field_value =~ REGEX return true end false end