Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class P01ValidUsernames {
- public static void Main(string[] args) {
- string[] usernamesArr = Console.ReadLine().Split(", ");
- foreach (string username in usernamesArr) {
- if (IsValidUsername(username)) {
- Console.WriteLine(username);
- }
- }
- }
- private static bool IsValidUsername(string username) {
- bool isValidLength = username.Length >= 3 && username.Length <= 16;
- bool isValidSymbol = true;
- foreach (char ch in username) {
- if (!char.IsLetterOrDigit(ch) && ch != '-' && ch != '_') {
- isValidSymbol = false;
- break;
- }
- }
- return isValidLength && isValidSymbol;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement