Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Validating string email?

Posted on 2006-04-02
14
Medium Priority
?
164 Views
Last Modified: 2013-11-24
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
0
Comment
Question by:EmailSurfer
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16354227
Best to validate with regex

http://www.codetoad.com/asp_email_reg_exp.asp
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16354245
In Java those escape character \ need to be doubled
0
 

Author Comment

by:EmailSurfer
ID: 16354251
Thanks

Can we use Regex in java servlet classes?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Expert Comment

by:Mayank S
ID: 16354264
Yes, sure. You need to import the correct package.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16354276
This shows how to do it for e-mail in Java:

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

Author Comment

by:EmailSurfer
ID: 16354342
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16354349
Patterns can be different and there are different ways to achieve the same thing
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16354381
Apparently, the expression that validates email addresses per RFC 822 is 6343 characters long ;-)

http://www.regular-expressions.info/email.html
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16354412
Try the one posted on Sun's web-site, for a start.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 120 total points
ID: 16354453
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
 
LVL 8

Expert Comment

by:colr__
ID: 16358366
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16426858
:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question