You are viewing a single comment's thread. Return to all 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"); } } }
} }
Seems like cookies are disabled on this browser, please enable them to open this website
Valid Username Regular Expression
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.util.regex.*; public class Solution {
} }