Java Email Authentication Regular Expression

I use the following regex

(".+@.+\\.[az]+") 

The bit accepts #@#.com as a valid email. Which template should I use?

+7
java regex email-validation
source share
6 answers

You must use apache-commons email authentication. You can get the jar file from here .

Here is a simple example of how to use it:

 import org.apache.commons.validator.routines.EmailValidator; boolean isValidEmail = EmailValidator.getInstance().isValid(emailAddress); 
+27
source share

Here is a webpage that explains what is better than I can: http://www.regular-expressions.info/email.html (EDIT: this seems a bit outdated since it refers to RFC 2822, which was replaced by RFC 5322)

And another interesting verification question: http://www.markussipila.info/pub/emailvalidator.php

Generally, the best strategy for checking your email address is simply trying to send him an email.

+2
source share

If someone wants to enter a non-existent email address, he will do it no matter what format you choose.

The only way to verify that the user owns the email that he entered is to send a confirmation (or activation) link to this address and ask the user to click it.

So do not try to make the life of your users more complicated. Checking for @ is good enough.

+1
source share

[A-Z0-9 ._% + -] +. @ [A-Z0-9.-] + [AZ] {2,4}

+1
source share

I usually use the following command:

 ([a-zA-Z0-9]+(?:[._+-][a-zA-Z0-9]+)*)@([a-zA-Z0-9]+(?:[.-][a-zA-Z0-9]+)*[.][a-zA-Z]{2,}) 
0
source share
 import java.util.regex.*; class ValidateEmailPhone{ public static void main(String args[]){ //phone no validation starts with 9 and of 10 digit System.out.println(Pattern.matches("[9]{1}[0-9]{9}", "9999999999")); //email validation System.out.println(Pattern.matches("[a-zA-Z0-9]{1,}[@]{1}[az]{5,}[.]{1}+[az]{3}", "abcd@gmail.com")); } } 
0
source share

All Articles