Advertisement
MartinZarev

Untitled

Mar 20th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P01.Valid_Username
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.            string[] input = Console.ReadLine().Split(", ",StringSplitOptions.None).ToArray();
  11.  
  12.             foreach (var username in input)
  13.             {
  14.                 if (ValidUsername(username))
  15.                 {
  16.                     Console.WriteLine(username);
  17.                 }
  18.             }
  19.  
  20.            
  21.         }
  22.  
  23.         static bool ValidUsername(string username)
  24.         {
  25.             bool isValid = true;
  26.  
  27.             if (username.Length<3||username.Length>16)
  28.             {
  29.                 return false;
  30.             }
  31.  
  32.             for (int i = 0; i < username.Length; i++)
  33.             {
  34.                 char currCh = username[i];
  35.  
  36.                 if (char.IsLetterOrDigit(currCh)||currCh=='-'|| currCh=='_')
  37.                 {
  38.                     isValid = false;
  39.                     break;
  40.                 }
  41.  
  42.             }
  43.  
  44.             return isValid;
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement