HackerRank Java- Valid Username Regular Expression
You are updating the username policy on your company's internal networking platform. According to the policy, a username is considered valid if all the following constraints are satisfied:
- import java.util.Scanner;
- class UsernameValidator {
- public static final String regularExpression = "^[a-zA-Z][\\w]{7,29}$";
- //public static final String regularExpression = null;
- }
-
-
- 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");
- }
- }
- }
- }