-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSolution.java
30 lines (23 loc) · 1000 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
class UsernameValidator {
// - This regular expression ensures that the username:
// - Starts with an alphabetic character [a-zA-Z].
// - Is followed by alphanumeric characters or underscores [a-zA-Z0-9_].
// - The total length of the username is between 8 and 30 characters.
// - indicates the start of the string and $ indicates the end, ensuring the whole string follows the pattern.
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");
}
}
}
}