Class: ValidationProfiler::Rules::EmailValidationRule
Constant Summary
collapse
- REGEX =
/^[^@]+@[^@]+\.[^@]+$/
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}, parent = nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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
if attributes[:message] == nil
"#{field_name} is not a valid email address"
else
attributes[:message]
end
end
|
#multiple_valid?(value) ⇒ Boolean
45
46
47
48
49
50
51
52
|
# 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) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/validation_profiler/rules/email_validation_rule.rb', line 23
def validate(obj, field, attributes = {}, parent = nil)
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
if field_value =~ REGEX
return true
end
false
end
|