• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
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 all,

I am starting a new thread as the same thread is old enough. I have a requirement to validate another email addresses. I am using the following pattern to validate my email address which is working for most of the email addresses:-
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,})$";.

I want a pattern for these emails 1) !#$%%^&*()[email protected], 2) [email protected], not allowed _before @ symbol, and 3) [email protected]_.net, subdomains should not allow end with a special character and must be with 2 - 4 characters.

Please guide me.

Thank you so much,

Naveen Katoch
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nav katoch wrote:Hi all,

I am starting a new thread as the same thread is old enough. I have a requirement to validate another email addresses. I am using the following pattern to validate my email address which is working for most of the email addresses:-
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,})$";.

I want a pattern for these emails 1) !#$%%^&*()[email protected], 2) [email protected], not allowed _before @ symbol, and 3) [email protected]_.net, subdomains should not allow end with a special character and must be with 2 - 4 characters.

Please guide me.

Thank you so much,

Naveen Katoch




Your current regex is almost 90% there. And your three new requirements could be added one at a time. Why don't you take a shot at doing the first one? .... what issue is currently stopping you?

Henry
 
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
Hi Henry,

I have fixed the first one with this public static String EMAIL_ADDRESS_VALIDATION_REGEX = "^[_A-Za-z0-9-[!#$%^&*()+]]+(\\.[_A-Za-z0-9-\\\\\"\\s]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; but not able to fixe the seond and third yet. Please guide.
Thanks,
Naveen Katoch
 
Ranch Hand
Posts: 275
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was trying the same 2-3 years back and after some days of research found there is no perfect regex to validate an email address.
Different countries have different patterns.
I finally ended up using Apache commons validator and no tester, product owner or user complained against the validations.
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic