Hello Programmers, In this post, you will know how to solve the Valid Username Regular Expression HackerRank Solution. This problem is a part of the HackerRank Java Programming Series.

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.
Valid Username Regular Expression HackerRank Solutions
Objective
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:
- The username consists of to characters inclusive. If the username consists of less than 8 or greater than 30 characters, then it is an invalid username.
Problem Statement: Click Here
Valid Username Regular Expression HackerRank Solutions
import java.util.Scanner; class UsernameValidator { public static final String regularExpression = "^[a-zA-Z][\\w]{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"); } } }
Disclaimer: The above Problem (Valid Username Regular Expression) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.
Next: Java Hashset HackerRank Solution