0

this is my code, it can validate single word but when i input example: John Smith the output is just John

package space;

import java.util.Scanner;

public class validate{

    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      boolean cusloop=false;
      String cusname="";
      while(cusloop==false){
            System.out.print("Enter customer name: ");
            cusname=sc.next();
            if(cusname.matches("[a-zA-Z ]+")){
                cusloop=true;
            }
            else{
                System.out.println("Invalid Input!");
                System.out.println("Input Letters Only!");
            }
        }
    }
}
Swarit Agarwal
  • 2,520
  • 1
  • 26
  • 33
yuriku
  • 1
  • 1

1 Answers1

0

just change

cusname = sc.nextLine();
Karan Malhotra
  • 125
  • 3
  • 11