Forums Register Login

Email Address using java regular expression

+Pie Number of slices to send: Send
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:
niceandsimple@example.com OK
a.little.unusual@example.com OK
much."more\ unusual"@example.com How this one?
very.unusual."@".unusual.com@example.com How this one?
very."(),:;<>[]".VERY."very\\\ @\"very".unusual@cool.example.com How this one?

Please help me out.

Thanks,

Naveen Katoch
+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
JavaMail with its InternetAddress is also an often-used library for parsing / validating email addresses.
+Pie Number of slices to send: Send
Thank you so much for all your inputs. I appreciate it.

Naveen
It's never done THAT before. Explain it to me tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1524 times.
Similar Threads
Email Validation
regexp on email address
i am validating email on server side
What's wrong in my regex comparison function ?
email validation using java code ."taking space."
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:24:12.