If the goal is to sanitize an email address, it's important to consult the RFCs that govern email standards. This process can be quite complex and challenging, especially if using Regex. A subset of valid email formats should be considered for simplicity.
For more information on this topic, refer to the following resources:
Valid characters in an email address include uppercase and lowercase English letters, digits, and specific special characters like ! # $ % & ' * + - / = ? ^ _ ` { | } ~. The use of periods (.) is allowed with certain restrictions.
It's crucial not to restrict user input based on assumptions about validity. Some users may have unique preferences or requirements for their email addresses, such as adding a plus sign (+) for filtering purposes.
Even after ensuring that an email address contains valid characters, there is no guarantee of its legitimacy.
If validating emails according to RFC guidelines is necessary, consider using the regex pattern provided by this source: Credit goes to this guy
(Regex pattern here)