[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

How to validate an email address

How do you validate an email address?

Must start with characters or digits, which may be separated with . or _  and contain the @ symbol. Top second and third level names must be separated with . character and end in top level domain (.com  .net  or  .co.uk).

The constructor should take a single STRING argument, the email address. If it's malformed (not valid) it should throw a MalformedEmailException with appropriate message.

Can anybody help, 'cos I'm lost here!

Many Thanks
0
DaveBarnes
Asked:
DaveBarnes
1 Solution
 
mbormannCommented:
what exactly u want?
0
 
dalehendCommented:
There are Perl Scripts that can validate an email address, not sure about any Java source.
0
 
dalehendCommented:
Wait! I did find Java package for regular expressions:
http://www.cacas.org/~wes/java/

Here is an expression from Perl FAQ to validate email addresses, but it does not handle all of them:
/^[\w.-]+\@([\w.-]\.)+\w+$/
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jsridharCommented:
Try Java Mail API and try to use EXPN command. EXPN returns the information about the particular email-id from the email server.

js.
0
 
jsabesanCommented:
if((checkstring==null)||(checkstring.indexOf("@")==1)||(checkstring.indexOf(".")=-1)||(checkstring.indexOf("@")==0) || (checkstring.indexOf("@")+1)==(checkstring.indexOf("."))||( checkstring.indexOf(".")+2)>=checkstring.length())
            return false;
      String subcheck = checkstring.substring(checkstring.indexOf(".")+1,checkstring.length());
      if (subcheck.length()>0)
      {
            int l = subcheck.length();
            char[] ch = new char[l];
            ch=subcheck.toCharArray();
              for(int i=0;i<l;i++)
            {
               if(Character.isDigit(ch[i]))
               {
                     return false;
               }
            }
      }
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now