Class: EmailValidationRule
Constant Summary
collapse
- REGEX =
/^[^@]+@[^@]+\.[^@]+$/
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}, parent = nil) ⇒ Object
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/validation_profiler/rules/rules.rb', line 288
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
|
#validate(obj, field, attributes = {}, parent = nil) ⇒ Object
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/validation_profiler/rules/rules.rb', line 305
def validate(obj, field, attributes = {}, parent = nil)
field_value = get_field_value(obj, field)
if !is_required?(field_value, attributes)
return true
end
if field_value =~ REGEX
return true
end
return false
end
|