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 2 of 2

Thread: String Problem

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question String Problem

    I have a problem with Payroll program I want to input only a alphabet for the name , if the
    user's input a number, for example, "sam4pl3" or "123 " the program will show a message "Number is not allowed" although the string is alphanumeric, then ask the user to input again, i

    thanks in advance.
        public static void main(String[] args) {
            Scanner dataIn = new Scanner(System.in);
     
            String firstName;
            String middleName;
            String lastName;
     
    	//NAME
    	System.out.print("Employees First Name: ");
            firstName = dataIn.nextLine();  //input first name 
            System.out.print("Employees Middle Name: ");
            middleName = dataIn.nextLine(); //input middle name
            System.out.print("Employees Last Name: ");
            lastName = dataIn.nextLine();   //input last name
     
    	Sample OUTPUT:
    	 Employees First Name: Juan 4 you
    	 Numbers are not allowed!
    	 Employees First Name: Juan
    	 Employees Middle Name: 143
      	 Numbers are not allowed!
    	 Employees Middle Name: 54
             Numbers are not allowed!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: String Problem

    I don't see a question. Presumably you wish to know how to do this. You can use a regular expression and the matches method in the String class or you can iterate over the String and examine each char to see if it is a digit. The Character class has a method to help you.
    Improving the world one idiot at a time!

Similar Threads

  1. Recursion /String problem
    By imrllyhandsome in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 9th, 2013, 10:37 PM
  2. Little String Problem
    By tyeeeee1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 9th, 2013, 08:02 PM
  3. Problem with string.compareTo();
    By Drasumok in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 30th, 2012, 04:31 PM
  4. [SOLVED] String problem
    By javabeg123 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 6th, 2011, 08:49 PM
  5. string==null or string.equals(null) problem
    By csharp100 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: November 4th, 2011, 08:17 AM