Valid Username Regular Expression

  • + 1 comment

    why is there a compalation error to my solution? do you have it too?

    class UsernameValidator { Scanner scan = new Scanner (System.in);

    for(int i=0;i<scan.nextInt();i++){
        String s=scan.nextLine();
        if(s.length()<8 || s.length()>30)
            System.out.println("Invalid");
        else{
            if(s.matches("^[a-zA-Z_]+$"))
                System.out.println("Valid");
            else
                System.out.println("Invalid");
    
        }
    }