• 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 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) !#$%%^&*()+@xxx.com, 2) SSS_@xxx.com, not allowed _before @ symbol, and 3) AAA@xxx.com_.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: 23951
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) !#$%%^&*()+@xxx.com, 2) SSS_@xxx.com, not allowed _before @ symbol, and 3) AAA@xxx.com_.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 Foreman
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.
 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic