Validating string email?


I am trying to require a basic validation rule to check an email address.

My plan was to use indexOf to test for the @ symbol.

I also wanted to check there was somewhere after the @ symbol an (.)

Does anyone know if I could use the indexOf method to test for the . after the @?

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Best to validate with regex
In Java those escape character \ need to be doubled
EmailSurferAuthor Commented:

Can we use Regex in java servlet classes?
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Mayank SAssociate Director - Product EngineeringCommented:
Yes, sure. You need to import the correct package.
Mayank SAssociate Director - Product EngineeringCommented:
Mayank SAssociate Director - Product EngineeringCommented:
This shows how to do it for e-mail in Java:
EmailSurferAuthor Commented:

Each of these links seem to recommend a different pattern.

I thought as the email address format can take many forms.

If I just tested these was a single @ and atleast 1 (.) symbol after the @. This was really all I could test for.

Does this seem correct?
Patterns can be different and there are different ways to achieve the same thing
Apparently, the expression that validates email addresses per RFC 822 is 6343 characters long ;-)
Mayank SAssociate Director - Product EngineeringCommented:
Try the one posted on Sun's web-site, for a start.
If i were doing this myself, i'd probably go for the regex recommended by that readable and knowledgeable expert on regular expressions at the last link i posted as it offers a good balance of exhaustiveness and practicality

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simplest algorithm:

Use java built in validator, then apply the folloiwng:

Check indexOf(@) > -1 and indexOf(.) > indexOf(@)
Split(@) - you should have an array length 2
spli(.) - you should have an array AT LEAST length 2

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.