Valid Username Regular Expression

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
    
        int n = scanner.nextInt();
        scanner.nextLine();
        for(int i = 0; i<n; i++){
            String word = scanner.nextLine();
            if(word.matches("^[a-zA-Z][a-zA-Z0-9_]{7,29}$")) System.out.println("Valid");
            else System.out.println("Invalid");
        }
    }
    

    }