my dog learned polymorphism*
The moose likes Other JSE/JEE APIs and the fly likes email validation using java code . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "email validation using java code ."taking space."" Watch "email validation using java code ."taking space."" New topic
Author

email validation using java code ."taking space."

Mannu Pal
Greenhorn

Joined: Dec 15, 2008
Posts: 8
Hi ,
I am using this code for email validation. the only problem with this is its taking space like as i have shown in exp code.
can any one help me to fix this bug.

String emailString = "aa hello@abv.com";
boolean isValidEMail = false;
String emailRegEx ="^([_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*.(([a-z]{2,3})|(aero|coop|info|museum)))?$";
Pattern pattern = Pattern.compile(emailRegEx);
Matcher matcher = pattern.matcher(emailString);
isValidEMail = matcher.find();
System.out.println("email result : "+isValidEMail);

email result : true

Regards ,
Mannu Pal.
Mannu Pal
Greenhorn

Joined: Dec 15, 2008
Posts: 8
Hi all,

i got the solution.
just replace this line of code and enjoy !!!

String emailRegEx ="^([_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*\\.(([A-Za-z]{2,3})|(aero|coop|info|museum)))?$";


Regards ,

Mannu Pal
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Valid email address can have spaces. See the specification. The JavaMail API also supplies a class that will do the validation for you.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

It's called javax.mail.internet.InternetAddress, and it is quite powerful. It even has methods to convert a list of email addresses (separated by commas) to InternetAddress[].


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: email validation using java code ."taking space."