Custom created single-line field - don't allow duplicate values

Custom created single-line field - don't allow duplicate values

In the system field labeled as "Email" when I try to enter email that already exists in our database, I am not allowed to do it and that is great.

Beside that field, our company is using another field (labeled as "Email 2") which is single-line field and we use it to fill it with secondary email address or sometimes addresses...

I know that I can create new email field and then edit properties for that field and mark "Don't allow duplicate values" and it is going to work... But since we are filling "Email 2" field sometimes with more than one email address, I have to use single-line field, not email field, because we are using commas to separate different email addresses.


Is it possible to write a function that is going to compare values inside the "Email" and "Email 2" field, and then when entering emails in the "Email 2" one cannot do it if the email is already present in the database ? (as an email or email 2)


Can you give me some links where I can inform myself about it?

If I have to change the data type of our "Email 2" field to be an email instead of single-line type, that is one option too. Maybe then the comparison will be simplified and the function won't be so complicated to write.