#C13543. Email Validation and Categorization
Email Validation and Categorization
Email Validation and Categorization
You are given a list of email addresses separated by spaces. Your task is to write a program that:
- Validates each email address using the following criteria:
- The email should match the regular expression: \( ^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$ \).
- Categorizes valid email addresses by their domain (i.e. the part after the '@' sign) and counts the number of valid emails per domain.
- Prints the list of invalid email addresses first (in the order they appear in the input), followed by a report of valid email counts by domain.
Note: The regular expression above ensures that the top-level domain (TLD) is between 2 to 6 alphabetic characters. Any email address not matching this pattern is considered invalid.
inputFormat
The input consists of a single line containing one or more email addresses separated by spaces.
\(Sample Input:\) user.name@example.com username@com
outputFormat
The output should have two sections:
- The first section titled Invalid Emails: lists each invalid email on a new line. If there are no invalid emails, nothing follows the title.
- The second section titled Valid Email Counts by Domain: lists each valid domain along with the count of valid emails, formatted as
domain: count
on individual lines.
There should be a blank line between the two sections.
## sampleuser.name@example.com username@example.com
Invalid Emails:
Valid Email Counts by Domain:
example.com: 2
</p>