We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Java
  3. Strings
  4. Valid Username Regular Expression
  5. Discussions

Valid Username Regular Expression

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 397 Discussions, By:

recency

Please Login in order to post a comment

  • thakurhitesh
    5 days ago+ 0 comments

    I found the following regex to be working:-

    "^[A-Za-z][a-zA-Z0-9_]{7,29}$" ;

    0|
    Permalink
  • 2001_codewithsu1
    2 weeks ago+ 0 comments

    import java.io.; import java.util.; import java.util.regex.*; public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    String empty = scanner.nextLine();
    Pattern specialCharactersString = Pattern.compile("[!@#$,'^%&*()+=|<>?{}\\[\\]~-]");
    Matcher hasSpecial;
    if (1 <= n && n <= 100) {
        String[] username = new String[n];
        for (int i = 0; i < n; i++) {
            username[i] = scanner.nextLine();
        }
        for (int i = 0; i < n; i++) {
            hasSpecial = specialCharactersString.matcher(username[i]);
            if ((username[i].length() >= 8) && (username[i].length() <= 30) && Character.isAlphabetic(username[i].charAt(0)) && !(hasSpecial.find())) {
                System.out.println("Valid");
            } else {
                System.out.println("Invalid");
            }
        }
    }
    

    } }

    2|
    Permalink
  • ligabeasttt
    1 month ago+ 1 comment
    public static final String regularExpression = "[a-zA-Z]\\w{7,29}";
    
    0|
    Permalink
  • ashwinmaurya9211
    2 months ago+ 0 comments

    you have to change only in "NULL" to this " ^[A-Za-z]\w{7,29}$"

    -2|
    Permalink
  • kritikraj83
    2 months ago+ 0 comments

    Here are the solution of Java Valid Username Regular Expression Hacker Rank Solution

    -2|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy