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