biryu2205 / Biryu

0 stars 0 forks source link

Valid Username Regular Expression #101

Closed biryu2205 closed 6 years ago

biryu2205 commented 7 years ago
import java.util.Scanner;

class UsernameValidator {

  public static final String regularExpression = "[a-zA-Z][a-zA-Z0-9_]{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");
      }
    }
  }

Link : - https://www.hackerrank.com/challenges/valid-username-checker/problem