Challenge: Email Validation
Swipe to start coding
Implement email validation by trimming any leading and trailing spaces from the string. Then, check the email's validity based on three conditions: there must be characters before the @
symbol, there must be characters after the @
, and the domain after the @
must contain a dot. If the email is valid, extract and display the domain (the part after the @
symbol, excluding the symbol itself).
- In the
validateEmail
method, find the index of the@
symbol in theemail
. - In the
validateEmail
method, find the index of the last dot (.
) symbol in theemail
. - Check that the
@
index is greater than0
, and the dot index is greater than the@
index and less than the length of the email minus 1. - In the
extractDomainFromEmail
method, find the index of the@
symbol in theemail
. - Extract and return the substring starting from the character immediately after
@
in theextractDomainFromEmail
method. - In the
main
method, trim any leading and trailing spaces from the email string.
Solution
solution.java
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.63
Challenge: Email Validation
Swipe to show menu
Swipe to start coding
Implement email validation by trimming any leading and trailing spaces from the string. Then, check the email's validity based on three conditions: there must be characters before the @
symbol, there must be characters after the @
, and the domain after the @
must contain a dot. If the email is valid, extract and display the domain (the part after the @
symbol, excluding the symbol itself).
- In the
validateEmail
method, find the index of the@
symbol in theemail
. - In the
validateEmail
method, find the index of the last dot (.
) symbol in theemail
. - Check that the
@
index is greater than0
, and the dot index is greater than the@
index and less than the length of the email minus 1. - In the
extractDomainFromEmail
method, find the index of the@
symbol in theemail
. - Extract and return the substring starting from the character immediately after
@
in theextractDomainFromEmail
method. - In the
main
method, trim any leading and trailing spaces from the email string.
Solution
solution.java
Thanks for your feedback!
Awesome!
Completion rate improved to 2.63single