Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sustring problem

    hi, I'm a first-level java learner, so my questions might seem really basic. but I don't really have a clue as to what I'm doing wrong. Can you guys please help out?

    I'm supposed to write a program that ask the user to input their email address. and The first letter and the last letter cannot be '@'. Moreover, '@' is supposed to be included somewhere in the middle of the input.
    I'm asking the user to input the data in PersonDB class. and I'm trying to write the validator for the email in another class called the Validator.

    so in the PersonDB class, I have:

    Code:
    //String email_String = Validator.getString(sc, "Enter Email Address: ");
    System.out.println("Enter Email Address: ");
    String email = sc.next();
    int strLength = email.length();
    System.out.println("" + strLength);
    Validator.validateEmail(email, strLength);
    c.setEmail(email);
    and in the Validator class, I have:
    Code:
    public boolean validateEmail(String emailValid, int strLength)
    	{
    		isvalid = false;
    
    		while ((emailValid.substring(0).equals('@'))
    				|| (emailValid[emailValid - 1].equals('@')))
    		{
    			System.out.println("ERROR! you cannot enter @ at the beginning or the end of your email address.\n");
    		}
    
    			if (int index = 1, index < strLength-1, index++)
    			{
    		                if (emailValid[index].equals("@"))
    		                {
    		                        return true;
    		                }
    		                 else
    		                 {
    		                          if (index == strLength-2)
    		                         {
    		                               return false;
    		                         }
    		                 }
    	}
    
    		return isvalid;
    	}
    Please help me out. I really don't know what else to do.
    Last edited by java_learner; 10-15-2005 at 03:42 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You are in the wrong forum. Perhaps one thing to learn is that Java is not at all the same as JavaScript, in spite of the confusingly similar names.


  •  

    Posting Permissions

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