Class: EmailValidationRule
Constant Summary
collapse
- REGEX =
/^[^@]+@[^@]+\.[^@]+$/
Instance Method Summary
collapse
#get_field_value, #is_required?
Instance Method Details
#error_message(field, attributes = {}) ⇒ Object
257
258
259
260
261
262
263
264
265
|
# File 'lib/validation_profiler/rules/rules.rb', line 257
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/validation_profiler/rules/rules.rb', line 268
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
|