Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Name Logic for Program

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Name Logic for Program

    I have user enter in a first name. how do I make sure that the first name is at least 2 characters long and only alphanumeric?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,308
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Name Logic for Program

    Take a look at the API for the String class...it has many methods to help accomplish what you want.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Name Logic for Program

    In case anyone is wondering how I accomplished it (this is using methods/objects) it turns out that I needed to just default names to First and Last not re-submit data.

    public void setfirstName(String first){
        if (first == "" || first.length() < 2)
                this.firstName = "First";
            else
                this.firstName = toProperCase(first);
    }

    public void setlastName(String last){
     if (last == "" || last.length() < 2)
                this.lastName = "Last";
            else
                this.lastName = toProperCase(last);
    }

    public static String toProperCase(String data){
          String firstLetter = data.substring(0,1).toUpperCase();
          String restLetters = data.substring(1).toLowerCase();
          return firstLetter + restLetters;
        }

Similar Threads

  1. need logic
    By arunjib in forum Java Theory & Questions
    Replies: 3
    Last Post: November 27th, 2011, 04:39 PM
  2. Replies: 1
    Last Post: May 14th, 2011, 04:57 PM
  3. Problem with the Logic
    By sudh in forum Java Theory & Questions
    Replies: 4
    Last Post: March 31st, 2011, 07:21 AM
  4. Need Help with Operators/ logic
    By codekiller in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2010, 09:25 AM
  5. help with the logic on this letter grade program.
    By etidd in forum Loops & Control Statements
    Replies: 2
    Last Post: January 28th, 2010, 08:14 PM