• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Email Address using java regular expression

 
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi team,

I am using the following pattern to validate my email address:-
static String EMAIL_MATCH_REG = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
which is working fine for
Valid email addresses:
[email protected] OK
[email protected] OK
much."more\ unusual"@example.com How this one?
very.unusual."@"[email protected] How this one?
very."(),:;<>[]".VERY."very\\\ @\"very"[email protected] How this one?

Please help me out.

Thanks,

Naveen Katoch
 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With this one
static String EMAIL_MATCH_REG = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-\\\\\"\\s]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

This one is working too
much."more\ unusual"@example.com OK now.

Thanks,

Naveen

 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how correct do you want to be? A legal email address can take lots of form, the spec is RFC822.

I use the Apace Common library to do it. No point in reinventing the wheel.
 
Sheriff
Posts: 28385
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Absolutely. You're just guessing at the rules, and if you do that then one day you're going to seriously annoy somebody by telling them their e-mail address isn't valid. If you really have to validate e-mail addresses (and you should try to design your system so you don't have to) then like Pat says, at least use code written by somebody who knows what they are doing.
 
Sheriff
Posts: 22841
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaMail with its InternetAddress is also an often-used library for parsing / validating email addresses.
 
nav katoch
Ranch Hand
Posts: 246
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for all your inputs. I appreciate it.

Naveen
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic