Class: EmailValidationRule
Constant Summary
collapse
- REGEX =
/^[^@]+@[^@]+\.[^@]+$/
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}) ⇒ Object
244
245
246
247
248
249
250
251
252
|
# File 'lib/validation_profiler/rules/rules.rb', line 244
def error_message(field, attributes = {})
if attributes[:message] == nil
"#{field} is not a valid email address"
else
attributes[:message]
end
end
|
#validate(obj, field, attributes = {}) ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
# File 'lib/validation_profiler/rules/rules.rb', line 255
def validate(obj, field, attributes = {})
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
|