HackerRank Java- Valid Username Regular Expression




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:



  1. import java.util.Scanner;
  2. class UsernameValidator {
  3. public static final String regularExpression = "^[a-zA-Z][\\w]{7,29}$";
  4. //public static final String regularExpression = null;
  5. }
  6. public class Solution {
  7. private static final Scanner scan = new Scanner(System.in);
  8. public static void main(String[] args) {
  9. int n = Integer.parseInt(scan.nextLine());
  10. while (n-- != 0) {
  11. String userName = scan.nextLine();
  12. if (userName.matches(UsernameValidator.regularExpression)) {
  13. System.out.println("Valid");
  14. } else {
  15. System.out.println("Invalid");
  16. }
  17. }
  18. }
  19. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube