Valid Username Regular Expression – Hacker Rank Solution


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 – Hacker Rank Solution

Code:

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 MultiplexCoder. This tutorial is only for Educational and Learning purposes.


 Tags:    hackerrank Java solutions | Functions Discussions | java | HackerRank | student analysis java hackerrank solution | challenges java hackerrank solution | hackerrank java basic certification solutions | hackerrank-java certification solutions | basic data types hackerrank solution in java | hackerrank java questions and answers | hackerrank java certification solutions | hackerrank java coding questions and answers | hackerrank-java certification solutions github | hackerrank java tutorial | hackerrank java interview questions | hackerrank java compiler | welcome to java hackerrank solution | codechef | google |2021

Previous
Next Post »