• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 23907
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 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic