• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

email validation using java code ."taking space."

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Valid email address can have spaces. See the specification. The JavaMail API also supplies a class that will do the validation for you.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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[].
reply
    Bookmark Topic Watch Topic
  • New Topic