• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 23928
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.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic