Validating string email?

Hello,

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
EmailSurferAsked:
Who is Participating?
 
CEHJCommented:
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
0
 
CEHJCommented:
Best to validate with regex

http://www.codetoad.com/asp_email_reg_exp.asp
0
 
CEHJCommented:
In Java those escape character \ need to be doubled
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
EmailSurferAuthor Commented:
Thanks

Can we use Regex in java servlet classes?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yes, sure. You need to import the correct package.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
Mayank SAssociate Director - Product EngineeringCommented:
This shows how to do it for e-mail in Java:

http://java.sun.com/developer/technicalArticles/releases/1.4regex/
0
 
EmailSurferAuthor Commented:
Thanks

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?
0
 
CEHJCommented:
Patterns can be different and there are different ways to achieve the same thing
0
 
CEHJCommented:
Apparently, the expression that validates email addresses per RFC 822 is 6343 characters long ;-)

http://www.regular-expressions.info/email.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Try the one posted on Sun's web-site, for a start.
0
 
colr__Commented:
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

colr__
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.