Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wants to trap email errors

 
joseph okon
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wrote the following code
public class EmailException {

static String email="";

// consttructor.
EmailException(String email) {

if( !isValidEmail(email))
System.out.println("Your Email must contain @ character!!");
//System.exit(0);
else

if(!appearTwice(email)) {

System.out.println("Your Email Address is Valid");


} else {
System.out.println("Two @ character can't be in an email address");
}

} //end of constructor.

// main method
public static void main(String args[]) {

EmailException ee=new EmailException(args[0]);
//ee.appearTwice(email);

} //end of main method.


private boolean isValidEmail(String email) {

return (email.indexOf("@") > 0);

} //end of isValidEmail method.






// to check the number of times @ character appears.

public boolean appearTwice(String email) {

int aIndex = 0;
int bIndex = 0;



for(int i = 0; i< email.length() {

aIndex = email.indexOf("@");

if(aIndex >= 1){

System.out.println("Two @ character can't be in an Email Address");
//System.exit(0);
}

}

return appearTwice(email);

}
}

it didn't work
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic