Validations in custom Ecto Type

Hi there, need advice.

It feels right to create a custom Ecto Type with normalization and validations inside to keep everything in one place. E.g. email type that downcases input, trims it and checks for @ presence.

The problem arises when you are trying to perform a search on this field. If user searches for a part of the email without the @, then the cast will raise.

What I need is to have the ability of fuzzy search. I don’t want to revert this field type back to a common string with a separate validations and normalization.

Any advice? How do you handle custom Ecto Types and text search?