DEV Community


Where to put regular expression checks?

An informatics engineering student that loves learning and programming.
・1 min read

Hello. I would like to know where should I check if a specific attribute matches with some regular expression. Should I do it in the class or in the database. For example imagine I have an User class, which has an email attribute, and I need to check if a given value for that property is correctly written. Also imagine I need to store the users in a database. Where should I check for the correctly written email, in the code inside the User class, in the database or both? Thank you.

Discussion (0)