This post is more about how to define a custom validation in ruby on rails. I am explaining the same by adding a custom validation for email.
Result we want I want to write something like this:
Here is how to do something like this:
Create a new file, i.e., email_format_validator.rb in the lib directory and paste following code there:
Define error message, i.e., Paste this sample code in config/locales/en.yml
Step 3: Auto load validator file, i.e., pastes these two lines in application.rb under config directory.
Thats it. Now restart your application. Your custom validator is defined :)