Results 1 to 6 of 6
  1. #1
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default Email Validation

    Java Code:
    // Checks for invalid characters
    //in email addresses
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.Scanner;
    
    public class EmailValidation {
       public static void main(String[] args) 
                                     throws Exception {
    	  String input=new String();
    			char[] id=new char[30];
    			char[] server=new char[30];
    	Matcher m;
    	Pattern p;
     	Scanner S=new Scanner(System.in);
          //Checks for email addresses starting with
          //inappropriate symbols like dots or @ signs.
           do
    	{ 
    		
    		System.out.println("Enter the email Id");
                   input = S.nextLine();
    		 p = Pattern.compile("^\\.|^\\@");
         		 m = p.matcher(input);
          		if (m.find())
             	System.err.println("Email addresses don't start" +
                                " with dots or @ signs this is not the valid address");
         		 //Checks for email addresses that start with
         		 //www. and prints a message if it does.
          		p = Pattern.compile("^www\\.");
         		 m = p.matcher(input);
          		if (m.find()) 
    		{
            		System.out.println("Email addresses don't start" +
                    	" with \"www.\", only web pages do,this is not the valid address");
          		}
          		p = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#]+");
          		m = p.matcher(input);
    	}while(m.find());
    	
    	System.out.println("It is valid address");
    	for(int i=0;i<input.length();i++)
    	{
    		do{
    		 id[i]=input.charAt(i);}while(input.charAt(i)!='@');
    		
    			for(int j=i;j<input.length();j++)
    			server[j]=input.charAt(j );
    		
    	}
    	System.out.println("Email Id:");
    	for(int i=0;i<id.length-1;i++)
    		System.out.print(id[i]);
    	System.out.println("");
    	
    	System.out.println("Server:");
    	for(int i=0;i<server.length-1;i++)
    		System.out.print(server[i]);
                
       }
    }
    for loop is not terminating.I dont know whats the problem last staments are not printing?
    Last edited by Eranga; 03-07-2011 at 07:42 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Java Code:
    do {
                    id[i] = input.charAt(i);
                } while (input.charAt(i) != '@');
    Think about the above code segment. You've not change the value of i in that loop, and there is no way to jump out.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    And one more thing, please use code tags when you are posting again in the forum. Unformated codes are really hard to read. If you don't know how to do that, check my forum signature. You can find a relevant link there.

  4. #4
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default

    how the value of i will be changed?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by juhiswt View Post
    how the value of i will be changed?
    It depends on what you really want to do.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Validation of Email
    By GreatWall in forum Web Frameworks
    Replies: 5
    Last Post: 09-26-2010, 11:13 AM
  2. Validation for multiple email addresses
    By dushyant1244 in forum Advanced Java
    Replies: 0
    Last Post: 09-24-2010, 06:00 AM
  3. Live Email Validation In Java
    By shameel in forum Web Frameworks
    Replies: 9
    Last Post: 01-05-2010, 05:42 AM
  4. String Tokenizer - Basic email validation
    By bobbyboyy in forum New To Java
    Replies: 3
    Last Post: 11-01-2009, 04:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •