Valid Username Regular Expression

Sort by

recency

|

483 Discussions

|

  • + 0 comments
    import java.util.Scanner;
    class UsernameValidator {
        public static final String regularExpression = "^[a-zA-Z][a-zA-Z0-9_]{7,29}$";
    }
    
    
    public class Solution {
        private static final Scanner scan = new Scanner(System.in);
        
        public static void main(String[] args) {
            int n = Integer.parseInt(scan.nextLine());
            while (n-- != 0) {
                String userName = scan.nextLine();
    
                if (userName.matches(UsernameValidator.regularExpression)) {
                    System.out.println("Valid");
                } else {
                    System.out.println("Invalid");
                }           
            }
        }
    }
    
  • + 0 comments

    Here is Valid Username Regular Expression Java solution - https://programmingoneonone.com/hackerrank-valid-username-regular-expression-solution-in-java.html

  • + 0 comments

    public static final String regularExpression = "^[a-zA-Z][\w]{7,29}$";

  • + 0 comments
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int size = scanner.nextInt();
            scanner.nextLine();
            for (int i = 0; i < size; i++) {
                System.out.println(scanner.nextLine().matches("[a-zA-Z][a-zA-Z0-9_]{7,29}") ? "Valid" : "Invalid");
            }
            scanner.close();
        }
    
  • + 0 comments
    public static final String regularExpression = "[A-Za-z]\\w{7,29}";