Java Solution

Java Valid Username Regular Expression – HackerRank Solution

0

Hello Friends, How are you? Today I am going to solve the HackerRank Java Valid Username Regular Expression Problem with a very easy explanation. This is the 23rd problem of Java on HackerRank. In this article, you will get more than one approach to solving this problem. So let’s start- {tocify} $title={Table of Contents} 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 8 to 30 characters inclusive. If the username consists of less than 8 or greater than 30 characters, then it is an invalid username.
  • The username can only contain alphanumeric characters and underscores (_). Alphanumeric characters describe the character set consisting of lowercase characters [a-z], uppercase characters [A-Z], and digits [0-9].
  • The first character of the username must be an alphabetic character, i.e., either lowercase character [A-Z] or uppercase character [A-Z].
Username Validity
Julia INVALID; Username length < 8 characters
Samantha VALID
Samantha_21 VALID
1Samantha INVALID; Username begins with non-alphabetic character
Samantha?10_2A INVALID; ‘?’ character not allowed

Update the value of regularExpression field in the UsernameValidator class so that the regular expression only matches with valid usernames. The first line of input contains an integer n, describing the total number of usernames. Each of the next n lines contains a string describing the username. The locked stub code reads the inputs and validates the username.

  • The username consists of any printable characters.
  • 1

Related Articles

Java Solution

Top 80+ JavaScript Interview Question and Answers for 2022

Hello Friends, How are you? Today I am sharing the top 80+...

Java Solution

Java Annotations HackerRank Solution with Explanation

Hello Friends, How are you? Today I will solve the HackerRank Java Annotations – Problem with a...

Java Solution

Java Regex – HackerRank Solution with Explanation

Hello Friends, How are you? Today I am going to solve the...

Java Solution

Java MD-5 HackerRank Solution with Explanation

Hello Friends, How are you? Today I will solve the HackerRank Java SHA-256 Problem...