Results 1 to 6 of 6
Thread: Email Validation
- 03-07-2011, 06:08 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 30
- Rep Power
- 0
Email Validation
for loop is not terminating.I dont know whats the problem last staments are not printing?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]); } }Last edited by Eranga; 03-07-2011 at 07:42 AM. Reason: code tags added
- 03-07-2011, 07:53 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.Java Code:do { id[i] = input.charAt(i); } while (input.charAt(i) != '@');
- 03-07-2011, 07:54 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 03-07-2011, 03:03 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 30
- Rep Power
- 0
how the value of i will be changed?
- 03-08-2011, 03:13 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 03-08-2011, 03:15 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you really trying to do there? Seems to me you want to split the email address and find what the domain is.
Similar Threads
-
Validation of Email
By GreatWall in forum Web FrameworksReplies: 5Last Post: 09-26-2010, 11:13 AM -
Validation for multiple email addresses
By dushyant1244 in forum Advanced JavaReplies: 0Last Post: 09-24-2010, 06:00 AM -
Live Email Validation In Java
By shameel in forum Web FrameworksReplies: 9Last Post: 01-05-2010, 05:42 AM -
String Tokenizer - Basic email validation
By bobbyboyy in forum New To JavaReplies: 3Last Post: 11-01-2009, 04:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks